J
JScoobyCed
Hi,
I have been trying several solutions lately as to how to manage a
non-blocking inputstream "listener".
I have a InputStream, from which I read in a separate Thread.
When data come, I know the first 4 bytes are the size of data coming.
Then I create a byte array to receive the number of expected bytes. When
I have received the correct amount, I reset the size of data to 0. This
tell me that next 4 bytes are a new message size.
My questions:
- is there a limit in the number of byte to read for an InputStream (I
could choose to use 10 bytes for the size of data to receive)
- is there a EOT byte or some byte value that would make the
InputStream.read(byte[] data) stop before the end of the expected size ?
(i.e.
<sniplet>
int expected = getSize();
byte[] data = new byte[expected];
int read = is.read(data);
System.out.println("Read: " + read + " bytes.");
</sniplet>
The displayed message always says that the read amount is lower than the
size expected if I send binary data (PNG image captured from a camera).
- is there a clean way to read 10-100 Kb binary data from an InoutStream ?
Thank you.
I have been trying several solutions lately as to how to manage a
non-blocking inputstream "listener".
I have a InputStream, from which I read in a separate Thread.
When data come, I know the first 4 bytes are the size of data coming.
Then I create a byte array to receive the number of expected bytes. When
I have received the correct amount, I reset the size of data to 0. This
tell me that next 4 bytes are a new message size.
My questions:
- is there a limit in the number of byte to read for an InputStream (I
could choose to use 10 bytes for the size of data to receive)
- is there a EOT byte or some byte value that would make the
InputStream.read(byte[] data) stop before the end of the expected size ?
(i.e.
<sniplet>
int expected = getSize();
byte[] data = new byte[expected];
int read = is.read(data);
System.out.println("Read: " + read + " bytes.");
</sniplet>
The displayed message always says that the read amount is lower than the
size expected if I send binary data (PNG image captured from a camera).
- is there a clean way to read 10-100 Kb binary data from an InoutStream ?
Thank you.