public static byte [ ] readStream ( InputStream is ) throws IOException { try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; byte [ ] buf = new byte [ 1024 * 10 ] ; int read ; while ( ( read = is . read ( buf ) ) >= 0 ) { baos . write ( buf , 0 , read ) ; } return baos . toByteArray ( ) ; } finally { is . close ( ) ; } }
Reads a byte array from a stream . Closes the stream after reading .