public boolean readFromFile ( int length ) throws IOException { // ensure that the read buffer is large enough if ( this . bufferData == null || this . bufferData . length < length ) { // ensure that the read buffer is not too large if ( length > Parameters . MAXIMUM_BUFFER_SIZE ) { LOGGER . warning ( "invalid read length: " + length ) ; return false ; } this . bufferData = new byte [ length ] ; this . bufferWrapper = ByteBuffer . wrap ( this . bufferData , 0 , length ) ; } // reset the buffer position and read the data into the buffer this . bufferPosition = 0 ; this . bufferWrapper . clear ( ) ; return this . inputChannel . read ( this . bufferWrapper ) == length ; }
Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position . If the capacity of the read buffer is too small a larger one is created automatically .