public BlockLogBuffer( ChannelBuffer target, ByteCounterMonitor monitor ) { this.target = target; this.monitor = monitor; clearInternalBuffer(); }
private void flush() { int howManyBytesToWrite = MAX_SIZE; target.writeBytes( byteArray, 0, howManyBytesToWrite ); monitor.bytesWritten( howManyBytesToWrite ); int pos = byteBuffer.position(); clearInternalBuffer(); byteBuffer.put( byteArray, howManyBytesToWrite, pos - howManyBytesToWrite ); }
/** * Signals the end of use for this buffer over this channel - first byte of * the chunk is set to the position of the buffer ( != 0, instead of * FULL_BLOCK_AND_MORE) and it is written to the channel. */ @Override public void close() { assert byteBuffer.position() > 1 : "buffer should contain more than the header"; assert byteBuffer.position() <= MAX_SIZE : "buffer should not be over full"; long howManyBytesToWrite = byteBuffer.position(); byteBuffer.put( 0, (byte) ( byteBuffer.position() - 1 ) ); byteBuffer.flip(); target.writeBytes( byteBuffer ); monitor.bytesWritten( howManyBytesToWrite ); clearInternalBuffer(); }