public static void readFully ( final InputStream inputStream , final byte [ ] buffer , final int offset , final int length ) throws IOException { if ( buffer . length < length + offset ) { throw new IllegalArgumentException ( "Buffer is too small" ) ; } int arrayOffset = offset ; int bytesToRead = length ; while ( bytesToRead > 0 ) { int bytesRead = inputStream . read ( buffer , arrayOffset , bytesToRead ) ; if ( bytesRead < 0 ) { throw new EOFException ( ) ; } bytesToRead -= bytesRead ; arrayOffset += bytesRead ; } }
Reads bytes from the input stream and puts them into the given byte buffer .