Top Description Inners Fields Constructors Methods
io.netty.handler.codec.compression

public Class Bzip2Encoder

extends MessageToByteEncoder<ByteBuf>
Class Inheritance
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelFuture, .ChannelHandlerContext, .ChannelPipeline, .ChannelPromise, io.netty.handler.codec.MessageToByteEncoder, io.netty.util.concurrent.EventExecutor, .PromiseNotifier

Compresses a ByteBuf using the Bzip2 algorithm. See Bzip2.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
Bzip2Encoder.State

Current state of stream.

Field Summary

Modifier and TypeField and Description
private Bzip2BlockCompressor
blockCompressor

The compressor for the current block.

private volatile ChannelHandlerContext
ctx

Used to interact with its ChannelPipeline and other handlers.

private Bzip2Encoder.State
private volatile boolean
finished

(@code true} if the compressed stream has been finished, otherwise false.

private final 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 final Bzip2BitWriter
writer

A writer that provides bit-level writes.

Constructor Summary

AccessConstructor and Description
public
Bzip2Encoder()

Creates a new bzip2 encoder with the maximum (900,000 byte) block size.

public
Bzip2Encoder(final int
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.
blockSizeMultiplier
)

Creates a new bzip2 encoder with the specified blockSizeMultiplier.

Method Summary

Modifier and TypeMethod and Description
public ChannelFuture
close()

Close this Bzip2Encoder and so finish the encoding.

public ChannelFuture
close(final ChannelPromise promise)

Close this Bzip2Encoder and so finish the encoding.

public void
close(final ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
final ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
private void
closeBlock(ByteBuf out)

Close current block and update streamCRC.

private ChannelHandlerContext
ctx()

protected void
encode(ChannelHandlerContext ctx, ByteBuf
the message to encode
in
,
ByteBuf
the ByteBuf into which the encoded message will be written
out
)

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf.
private ChannelFuture
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public boolean
isClosed()

Returns true if and only if the end of the compressed stream has been reached.

Inherited from io.netty.handler.codec.MessageToByteEncoder:
acceptOutboundMessageallocateBufferisPreferDirectwrite

Field Detail

blockCompressorback to summary
private Bzip2BlockCompressor blockCompressor

The compressor for the current block.

ctxback to summary
private volatile ChannelHandlerContext ctx

Used to interact with its ChannelPipeline and other handlers.

currentStateback to summary
private Bzip2Encoder.State currentState
finishedback to summary
private volatile boolean finished

(@code true} if the compressed stream has been finished, otherwise false.

streamBlockSizeback to summary
private final int streamBlockSize

The declared maximum block size of the stream (before final run-length decoding).

streamCRCback to summary
private int streamCRC

The merged CRC of all blocks compressed so far.

writerback to summary
private final Bzip2BitWriter writer

A writer that provides bit-level writes.

Constructor Detail

Bzip2Encoderback to summary
public Bzip2Encoder()

Creates a new bzip2 encoder with the maximum (900,000 byte) block size.

Bzip2Encoderback to summary
public Bzip2Encoder(final int blockSizeMultiplier)

Creates a new bzip2 encoder with the specified blockSizeMultiplier.

Parameters
blockSizeMultiplier:int

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.

Method Detail

closeback to summary
public ChannelFuture close()

Close this Bzip2Encoder and so finish the encoding. The returned ChannelFuture will be notified once the operation completes.

closeback to summary
public ChannelFuture close(final ChannelPromise promise)

Close this Bzip2Encoder and so finish the encoding. The given ChannelFuture will be notified once the operation completes and will also be returned.

closeback to summary
public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.close.

thrown if an error occurs

closeBlockback to summary
private void closeBlock(ByteBuf out)

Close current block and update streamCRC.

ctxback to summary
private ChannelHandlerContext ctx()
encodeback to summary
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Doc from io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

in:ByteBuf

the message to encode

out:ByteBuf

the ByteBuf into which the encoded message will be written

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
finishEncodeback to summary
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise)
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Returns true if and only if the end of the compressed stream has been reached.

io.netty.handler.codec.compression back to summary

private final Enum Bzip2Encoder.State

extends Enum<Bzip2Encoder.State>
Class Inheritance

Current state of stream.

Field Summary

Modifier and TypeField and Description
public static final Bzip2Encoder.State
public static final Bzip2Encoder.State
public static final Bzip2Encoder.State
public static final Bzip2Encoder.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Bzip2Encoder.State
public static Bzip2Encoder.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLOSE_BLOCKback to summary
public static final Bzip2Encoder.State CLOSE_BLOCK
INITback to summary
public static final Bzip2Encoder.State INIT
INIT_BLOCKback to summary
public static final Bzip2Encoder.State INIT_BLOCK
WRITE_DATAback to summary
public static final Bzip2Encoder.State WRITE_DATA

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static Bzip2Encoder.State valueOf(String name)
valuesback to summary
public static Bzip2Encoder.State[] values()