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
public class Bzip2Encoder extends MessageToByteEncoder<ByteBuf>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBzip2Encoder.StateCurrent state of stream.-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private Bzip2BlockCompressorblockCompressorThe compressor for the current block.private ChannelHandlerContextctxUsed to interact with itsChannelPipelineand other handlers.private Bzip2Encoder.StatecurrentStateprivate booleanfinished(@code true} if the compressed stream has been finished, otherwisefalse.private intstreamBlockSizeThe declared maximum block size of the stream (before final run-length decoding).private intstreamCRCThe merged CRC of all blocks compressed so far.private Bzip2BitWriterwriterA writer that provides bit-level writes.
-
Constructor Summary
Constructors Constructor 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 specifiedblockSizeMultiplier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChannelFutureclose()Close thisBzip2Encoderand so finish the encoding.voidclose(ChannelHandlerContext ctx, ChannelPromise promise)CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.ChannelFutureclose(ChannelPromise promise)Close thisBzip2Encoderand so finish the encoding.private voidcloseBlock(ByteBuf out)Close current block and updatestreamCRC.private ChannelHandlerContextctx()protected voidencode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)Encode a message into aByteBuf.private ChannelFuturefinishEncode(ChannelHandlerContext ctx, ChannelPromise promise)voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.booleanisClosed()Returnstrueif 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 Detail
-
currentState
private Bzip2Encoder.State currentState
-
writer
private final Bzip2BitWriter writer
A writer that provides bit-level writes.
-
streamBlockSize
private final int streamBlockSize
The declared maximum block size of the stream (before final run-length decoding).
-
streamCRC
private int streamCRC
The merged CRC of all blocks compressed so far.
-
blockCompressor
private Bzip2BlockCompressor blockCompressor
The compressor for the current block.
-
finished
private volatile boolean finished
(@code true} if the compressed stream has been finished, otherwisefalse.
-
ctx
private volatile ChannelHandlerContext ctx
Used to interact with itsChannelPipelineand other handlers.
-
-
Constructor Detail
-
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.9will usually be the best value to use.
-
-
Method Detail
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
Description copied from class:MessageToByteEncoderEncode a message into aByteBuf. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToByteEncoder<ByteBuf>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToByteEncoderbelongs toin- the message to encodeout- theByteBufinto which the encoded message will be written- Throws:
java.lang.Exception- is thrown if an error occurs
-
isClosed
public boolean isClosed()
Returnstrueif and only if the end of the compressed stream has been reached.
-
close
public ChannelFuture close()
Close thisBzip2Encoderand so finish the encoding. The returnedChannelFuturewill be notified once the operation completes.
-
close
public ChannelFuture close(ChannelPromise promise)
Close thisBzip2Encoderand so finish the encoding. The givenChannelFuturewill be notified once the operation completes and will also be returned.
-
close
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from class:ChannelOutboundHandlerAdapterCallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
closein interfaceChannelOutboundHandler- Overrides:
closein classChannelOutboundHandlerAdapter- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
finishEncode
private ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelPromise promise)
-
ctx
private ChannelHandlerContext ctx()
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
-