public BlockLogReader( ChannelBuffer source ) { this.source = source; readNextBlock(); }
/** * Reads everything that can be read from the channel. Stops when a chunk * starting with a non zero byte is met. */ private void readToTheEnd() { while ( moreBlocks ) { readNextBlock(); } } }
/** * Reads in at most {@code maxBytesWanted} in {@code dst} but never more * than a chunk. * * @param dst The buffer to write the reads bytes to * @param maxBytesWanted The maximum number of bytes to read. * @return The number of bytes actually read */ private int readAsMuchAsPossible( ByteBuffer dst, int maxBytesWanted ) { if ( byteBuffer.remaining() == 0 && moreBlocks ) { readNextBlock(); } int bytesToRead = Math.min( maxBytesWanted, byteBuffer.remaining() ); dst.put( byteArray, byteBuffer.position(), bytesToRead ); byteBuffer.position( byteBuffer.position() + bytesToRead ); return bytesToRead; }