Looking to read in some bytes over a socket using an inputStream. The bytes sent by the server may be of variable quantity, and the client doesn\'t know in advance the lengt
Assuming the sender closes the stream at the end of the data:
ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; while(true) { int n = is.read(buf); if( n < 0 ) break; baos.write(buf,0,n); } byte data[] = baos.toByteArray();