Class Bzip2Encoder
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToByteEncoder<ByteBuf>
io.netty.handler.codec.compression.Bzip2Encoder
- All Implemented Interfaces:
ChannelHandler
,ChannelOutboundHandler
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Bzip2BlockCompressor
The compressor for the current block.private ChannelHandlerContext
Used to interact with itsChannelPipeline
and other handlers.private Bzip2Encoder.State
private boolean
(@code true} if the compressed stream has been finished, otherwisefalse
.private final int
The declared maximum block size of the stream (before final run-length decoding).private int
The merged CRC of all blocks compressed so far.private final Bzip2BitWriter
A writer that provides bit-level writes. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new bzip2 encoder with the maximum (900,000 byte) block size.Bzip2Encoder
(int blockSizeMultiplier) Creates a new bzip2 encoder with the specifiedblockSizeMultiplier
. -
Method Summary
Modifier and TypeMethodDescriptionclose()
Close thisBzip2Encoder
and so finish the encoding.void
close
(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.close
(ChannelPromise promise) Close thisBzip2Encoder
and so finish the encoding.private void
closeBlock
(ByteBuf out) Close current block and updatestreamCRC
.private ChannelHandlerContext
ctx()
protected void
encode
(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) Encode a message into aByteBuf
.private ChannelFuture
finishEncode
(ChannelHandlerContext ctx, ChannelPromise promise) void
Do nothing by default, sub-classes may override this method.boolean
isClosed()
Returnstrue
if and only if the end of the compressed stream has been reached.Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, write
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught, handlerRemoved
-
Field Details
-
currentState
-
writer
A writer that provides bit-level writes. -
streamBlockSize
private final int streamBlockSizeThe declared maximum block size of the stream (before final run-length decoding). -
streamCRC
private int streamCRCThe merged CRC of all blocks compressed so far. -
blockCompressor
The compressor for the current block. -
finished
private volatile boolean finished(@code true} if the compressed stream has been finished, otherwisefalse
. -
ctx
Used to interact with itsChannelPipeline
and other handlers.
-
-
Constructor Details
-
Bzip2Encoder
public Bzip2Encoder()Creates a new bzip2 encoder with the maximum (900,000 byte) block size. -
Bzip2Encoder
public Bzip2Encoder(int blockSizeMultiplier) Creates a new bzip2 encoder with the specifiedblockSizeMultiplier
.- Parameters:
blockSizeMultiplier
- The Bzip2 block size as a multiple of 100,000 bytes (minimum1
, maximum9
). 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.
-
-
Method Details
-
encode
Description copied from class:MessageToByteEncoder
Encode a message into aByteBuf
. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToByteEncoder<ByteBuf>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToByteEncoder
belongs toin
- the message to encodeout
- theByteBuf
into which the encoded message will be written- Throws:
Exception
- is thrown if an error occurs
-
closeBlock
Close current block and updatestreamCRC
. -
isClosed
public boolean isClosed()Returnstrue
if and only if the end of the compressed stream has been reached. -
close
Close thisBzip2Encoder
and so finish the encoding. The returnedChannelFuture
will be notified once the operation completes. -
close
Close thisBzip2Encoder
and so finish the encoding. The givenChannelFuture
will be notified once the operation completes and will also be returned. -
close
Description copied from class:ChannelOutboundHandlerAdapter
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
close
in interfaceChannelOutboundHandler
- Overrides:
close
in classChannelOutboundHandlerAdapter
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
finishEncode
-
ctx
-
handlerAdded
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
Exception
-