Class LzfEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<ByteBuf>
-
- io.netty.handler.codec.compression.LzfEncoder
-
- All Implemented Interfaces:
ChannelHandler
,ChannelOutboundHandler
public class LzfEncoder extends MessageToByteEncoder<ByteBuf>
Compresses aByteBuf
using the LZF format.See original LZF package and LZF format for full description.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description LzfEncoder()
Creates a new LZF encoder with the most optimal available methods for underlying data access.LzfEncoder(boolean safeInstance)
Deprecated.Use the constructor without thesafeInstance
parameter.LzfEncoder(boolean safeInstance, int totalLength)
Deprecated.Use the constructor without thesafeInstance
parameter.LzfEncoder(boolean safeInstance, int totalLength, int compressThreshold)
Deprecated.Use the constructor without thesafeInstance
parameter.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
Encode a message into aByteBuf
.void
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, write
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, 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, handlerAdded
-
-
-
-
Constructor Detail
-
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)
withtrue
param.
-
LzfEncoder
@Deprecated public LzfEncoder(boolean safeInstance)
Deprecated.Use the constructor without thesafeInstance
parameter.Creates a new LZF encoder with specified encoding instance.- Parameters:
safeInstance
- Iftrue
encoder will useChunkEncoder
that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoder
implementation that uses Sun JDK'sUnsafe
class (which may be included by other JDK's as well).
-
LzfEncoder
@Deprecated public LzfEncoder(boolean safeInstance, int totalLength)
Deprecated.Use the constructor without thesafeInstance
parameter.Creates a new LZF encoder with specified encoding instance and compressThreshold.- Parameters:
safeInstance
- Iftrue
encoder will useChunkEncoder
that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoder
implementation that uses Sun JDK'sUnsafe
class (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 public LzfEncoder(boolean safeInstance, int totalLength, int compressThreshold)
Deprecated.Use the constructor without thesafeInstance
parameter.Creates a new LZF encoder with specified settings.- Parameters:
safeInstance
- Iftrue
encoder will useChunkEncoder
that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimizedChunkEncoder
implementation that uses Sun JDK'sUnsafe
class (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 Detail
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
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:
java.lang.Exception
- is thrown if an error occurs
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
-