question: private static byte [ ] streamToBytes ( InputStream in , int length ) throws IOException { byte [ ] bytes = new byte [ length ] ; int count ; int pos = 0 ; while ( pos < length && ( ( count = in . read ( bytes , pos , length - pos ) ) != - 1 ) ) { pos += count ; } if ( pos != length ) { throw new IOException ( "Expected " + length + " bytes, read " + pos + " bytes" ) ; } return bytes ; }
target:  Reads the contents of an InputStream into a byte[].