Class LzfEncoder
java.lang.Object
- All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Compresses a
ByteBuf using the LZF format.
See original LZF package and LZF format for full description.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new LZF encoder with the most optimal available methods for underlying data access.LzfEncoder(boolean safeInstance) Deprecated.LzfEncoder(boolean safeInstance, int totalLength) Deprecated.Use the constructor without thesafeInstanceparameter.LzfEncoder(boolean safeInstance, int totalLength, int compressThreshold) Deprecated.Use the constructor without thesafeInstanceparameter.LzfEncoder(int totalLength) Creates a new LZF encoder with specified total length of encoded chunk.LzfEncoder(int totalLength, int compressThreshold) Creates a new LZF encoder with specified settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidencode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) Encode a message into aByteBuf.voidDo nothing by default, sub-classes may override this method.Methods inherited from class MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, writeMethods inherited from class ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
exceptionCaught, handlerAdded
-
Constructor Details
-
LzfEncoder
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 useLzfEncoder(boolean)withtrueparam. -
LzfEncoder
Deprecated.Use the constructor without thesafeInstanceparameter.Creates a new LZF encoder with specified encoding instance.- Parameters:
safeInstance- Iftrueencoder will useChunkEncoderthat only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoderimplementation that uses Sun JDK'sUnsafeclass (which may be included by other JDK's as well).
-
LzfEncoder
Deprecated.Use the constructor without thesafeInstanceparameter.Creates a new LZF encoder with specified encoding instance and compressThreshold.- Parameters:
safeInstance- Iftrueencoder will useChunkEncoderthat only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoderimplementation that uses Sun JDK'sUnsafeclass (which may be included by other JDK's as well).totalLength- 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.
-
LzfEncoder
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- 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.
-
LzfEncoder
public LzfEncoder(int totalLength, int compressThreshold) Creates a new LZF encoder with specified settings.- Parameters:
totalLength- 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- 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.
-
LzfEncoder
Deprecated.Use the constructor without thesafeInstanceparameter.Creates a new LZF encoder with specified settings.- Parameters:
safeInstance- Iftrueencoder will useChunkEncoderthat only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoderimplementation that uses Sun JDK'sUnsafeclass (which may be included by other JDK's as well).totalLength- 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- 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 Details
-
encode
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:
Exception- is thrown if an error occurs
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
safeInstanceparameter.