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

public Class LzfEncoder

extends MessageToByteEncoder<ByteBuf>
Class Inheritance
Imports
com.ning.compress.BufferRecycler, com.ning.compress.lzf.ChunkEncoder, .LZFChunk, .LZFEncoder, com.ning.compress.lzf.util.ChunkEncoderFactory, io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, io.netty.handler.codec.MessageToByteEncoder

Compresses a ByteBuf using the LZF format.

See original LZF package and LZF format for full description.

Field Summary

Modifier and TypeField and Description
private final int
compressThreshold

Compress threshold for LZF format.

private final ChunkEncoder
encoder

Underlying decoder in use.

private static final int
MIN_BLOCK_TO_COMPRESS

Minimum block size ready for compression.

private final BufferRecycler
recycler

Object that handles details of buffer recycling.

Constructor Summary

AccessConstructor and Description
public
LzfEncoder()

Creates a new LZF encoder with the most optimal available methods for underlying data access.

public
LzfEncoder(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
)

Creates a new LZF encoder with specified encoding instance.

public
LzfEncoder(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
,
int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
)

Creates a new LZF encoder with specified encoding instance and compressThreshold.

public
LzfEncoder(int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
)

Creates a new LZF encoder with specified total length of encoded chunk.

public
LzfEncoder(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
,
int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
,
int
Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.
compressThreshold
)

Creates a new LZF encoder with specified settings.

Method Summary

Modifier and TypeMethod and Description
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 int
encodeCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

private static int
encodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

Use lzf uncompressed format to encode a piece of input.

public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
private static int
lzfEncodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

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

Field Detail

compressThresholdback to summary
private final int compressThreshold

Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.

When the value is less than ChunkEncoder#MIN_BLOCK_TO_COMPRESS, since LZF will not compress data that is less than ChunkEncoder#MIN_BLOCK_TO_COMPRESS, compressThreshold will not work.

See Also
ChunkEncoder#MIN_BLOCK_TO_COMPRESS
encoderback to summary
private final ChunkEncoder encoder

Underlying decoder in use.

MIN_BLOCK_TO_COMPRESSback to summary
private static final int MIN_BLOCK_TO_COMPRESS

Minimum block size ready for compression. Blocks with length less than MIN_BLOCK_TO_COMPRESS will write as uncompressed.

recyclerback to summary
private final BufferRecycler recycler

Object that handles details of buffer recycling.

Constructor Detail

LzfEncoderback to summary
public LzfEncoder()

Creates a new LZF encoder with the most optimal available methods for underlying data access. It will "unsafe" instance if one can be used on current JVM. It should be safe to call this constructor as implementations are dynamically loaded; however, on some non-standard platforms it may be necessary to use LzfEncoder(boolean) with true param.

LzfEncoderback to summary
public LzfEncoder(boolean safeInstance)

Creates a new LZF encoder with specified encoding instance.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

LzfEncoderback to summary
public LzfEncoder(boolean safeInstance, int totalLength)

Creates a new LZF encoder with specified encoding instance and compressThreshold.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

LzfEncoderback to summary
public LzfEncoder(int totalLength)

Creates a new LZF encoder with specified total length of encoded chunk. You can configure it to encode your data flow more efficient if you know the average size of messages that you send.

Parameters
totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

LzfEncoderback to summary
public LzfEncoder(boolean safeInstance, int totalLength, int compressThreshold)

Creates a new LZF encoder with specified settings.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

compressThreshold:int

Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.

Method Detail

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
encodeCompressback to summary
private int encodeCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)
encodeNonCompressback to summary
private static int encodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

Use lzf uncompressed format to encode a piece of input.

handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
lzfEncodeNonCompressback to summary
private static int lzfEncodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)