static void readAllBytesOrFail ( InputStream in , byte [ ] buffer ) throws IOException { int read = readAllBytes ( in , buffer ) ; if ( read != buffer . length ) { throw new EOFException ( String . format ( "Expected %d bytes but read %d bytes." , buffer . length , read ) ) ; } }
Fills the buffer from the input stream . Throws exception if EOF occurs before buffer is filled .