public static void readFully ( InputStream in , byte [ ] b ) throws IOException , EOFException { final int length = b . length ; int total = 0 ; while ( total < length ) { int amt = in . read ( b , total , length - total ) ; if ( amt < 0 ) { throw new EOFException ( ) ; } total += amt ; } }
Reads as many bytes from the stream as is necessary to fill the given byte array . An EOFException is thrown if the stream end is encountered .