public boolean readBufferFromFileChannel ( Buffer buffer ) throws IOException { checkArgument ( fileChannel . size ( ) - fileChannel . position ( ) > 0 ) ; // Read header header . clear ( ) ; fileChannel . read ( header ) ; header . flip ( ) ; final boolean isBuffer = header . getInt ( ) == 1 ; final int size = header . getInt ( ) ; if ( size > buffer . getMaxCapacity ( ) ) { throw new IllegalStateException ( "Buffer is too small for data: " + buffer . getMaxCapacity ( ) + " bytes available, but " + size + " needed. This is most likely due to an serialized event, which is larger than the buffer size." ) ; } checkArgument ( buffer . getSize ( ) == 0 , "Buffer not empty" ) ; fileChannel . read ( buffer . getNioBuffer ( 0 , size ) ) ; buffer . setSize ( size ) ; if ( ! isBuffer ) { buffer . tagAsEvent ( ) ; } return fileChannel . size ( ) - fileChannel . position ( ) == 0 ; }
Reads data from the object s file channel into the given buffer .