byte[] b = new byte[10000];
len = readerIn.read(b); // InputStream
My byte size is 10000, but the InputStream
size may be lower or higher. Is there a way to read only the size of data that comes into the InputStream
?
byte[] b = new byte[10000];
len = readerIn.read(b); // InputStream
My byte size is 10000, but the InputStream
size may be lower or higher. Is there a way to read only the size of data that comes into the InputStream
?
You can use the ByteArrayOutputStream
for this
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int reads = is.read();
while(reads != -1){
baos.write(reads);
reads = is.read();
}
byte[] data = baos.toByteArray();
the data array has the proper size and contains all the data of or InputStream
You can read the totally size of data reading byte by byte by no putting paramenter in read method:
len = readerIn.read();
You can readstill the end of the stream
while((readerIn.read())!=-1){
[your code]
}