public class Bzip2Encoder extends MessageToByteEncoder<ByteBuf>
| Modifier and Type | Class and Description |
|---|---|
private static class |
Bzip2Encoder.State
Current state of stream.
|
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private Bzip2BlockCompressor |
blockCompressor
The compressor for the current block.
|
private ChannelHandlerContext |
ctx
Used to interact with its
ChannelPipeline and other handlers. |
private Bzip2Encoder.State |
currentState |
private boolean |
finished
(@code true} if the compressed stream has been finished, otherwise
false. |
private int |
streamBlockSize
The declared maximum block size of the stream (before final run-length decoding).
|
private int |
streamCRC
The merged CRC of all blocks compressed so far.
|
private Bzip2BitWriter |
writer
A writer that provides bit-level writes.
|
| Constructor and Description |
|---|
Bzip2Encoder()
Creates a new bzip2 encoder with the maximum (900,000 byte) block size.
|
Bzip2Encoder(int blockSizeMultiplier)
Creates a new bzip2 encoder with the specified
blockSizeMultiplier. |
| Modifier and Type | Method and Description |
|---|---|
ChannelFuture |
close()
Close this
Bzip2Encoder and so finish the encoding. |
void |
close(ChannelHandlerContext ctx,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
ChannelFuture |
close(ChannelPromise promise)
Close this
Bzip2Encoder and so finish the encoding. |
private void |
closeBlock(ByteBuf out)
Close current block and update
streamCRC. |
private ChannelHandlerContext |
ctx() |
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf in,
ByteBuf out)
Encode a message into a
ByteBuf. |
private ChannelFuture |
finishEncode(ChannelHandlerContext ctx,
ChannelPromise promise) |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isClosed()
Returns
true if and only if the end of the compressed stream has been reached. |
acceptOutboundMessage, allocateBuffer, isPreferDirect, writebind, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaught, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerRemovedprivate Bzip2Encoder.State currentState
private final Bzip2BitWriter writer
private final int streamBlockSize
private int streamCRC
private Bzip2BlockCompressor blockCompressor
private volatile boolean finished
false.private volatile ChannelHandlerContext ctx
ChannelPipeline and other handlers.public Bzip2Encoder()
public Bzip2Encoder(int blockSizeMultiplier)
blockSizeMultiplier.blockSizeMultiplier - The Bzip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9).
Larger block sizes require more memory for both compression and decompression,
but give better compression ratios. 9 will usually be the best value to use.protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
MessageToByteEncoderByteBuf. This method will be called for each written message that can be handled
by this encoder.encode in class MessageToByteEncoder<ByteBuf>ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs toin - the message to encodeout - the ByteBuf into which the encoded message will be writtenjava.lang.Exception - is thrown if an error occurspublic boolean isClosed()
true if and only if the end of the compressed stream has been reached.public ChannelFuture close()
Bzip2Encoder and so finish the encoding.
The returned ChannelFuture will be notified once the operation completes.public ChannelFuture close(ChannelPromise promise)
Bzip2Encoder and so finish the encoding.
The given ChannelFuture will be notified once the operation
completes and will also be returned.public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close in interface ChannelOutboundHandlerclose in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occursprivate ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelPromise promise)
private ChannelHandlerContext ctx()
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterjava.lang.Exception