public class Lz4FrameEncoder extends MessageToByteEncoder<ByteBuf>
ByteBuf
using the LZ4 format.
See original LZ4 website
and LZ4 block format
for full description.
Since the original LZ4 block format does not contains size of compressed block and size of original data
this encoder uses format like LZ4 Java library
written by Adrien Grand and approved by Yann Collet (author of original LZ4 library).
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Magic * Token * Compressed * Decompressed * Checksum * + * LZ4 compressed *
* * * length * length * * * block *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *ChannelHandler.Sharable, ChannelHandler.Skip
Constructor and Description |
---|
Lz4FrameEncoder()
Creates the fastest LZ4 encoder with default block size (64 KB)
and xxhash hashing for Java, based on Yann Collet's work available at
Google Code.
|
Lz4FrameEncoder(boolean highCompressor)
Creates a new LZ4 encoder with hight or fast compression, default block size (64 KB)
and xxhash hashing for Java, based on Yann Collet's work available at
Google Code.
|
Lz4FrameEncoder(LZ4Factory factory,
boolean highCompressor,
int blockSize,
Checksum checksum)
Creates a new customizable LZ4 encoder.
|
Modifier and Type | Method and Description |
---|---|
ChannelFuture |
close()
Close this
Lz4FrameEncoder and so finish the encoding. |
void |
close(ChannelHandlerContext ctx,
ChannelPromise promise)
Calls
ChannelHandlerContext.close(ChannelPromise) to forward
to the next ChannelHandler in the ChannelPipeline . |
ChannelFuture |
close(ChannelPromise promise)
Close this
Lz4FrameEncoder and so finish the encoding. |
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf in,
ByteBuf out)
Encode a message into a
ByteBuf . |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isClosed()
Returns
true if and only if the compressed stream has been finished. |
acceptOutboundMessage, allocateBuffer, write
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, connect, deregister, disconnect, exceptionCaught, flush, handlerRemoved, isSharable, read, userEventTriggered
public Lz4FrameEncoder()
public Lz4FrameEncoder(boolean highCompressor)
highCompressor
- if true
codec will use compressor which requires more memory
and is slower but compresses more efficientlypublic Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum)
factory
- user customizable net.jpountz.lz4.LZ4Factory
instance
which may be JNI bindings to the original C implementation, a pure Java implementation
or a Java implementation that uses the Unsafe
highCompressor
- if true
codec will use compressor which requires more memory
and is slower but compresses more efficientlyblockSize
- the maximum number of bytes to try to compress at once,
must be >= 64 and <= 32 Mchecksum
- the Checksum
instance to use to check data for integrityprotected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
MessageToByteEncoder
ByteBuf
. This method will be called for each written message that can be handled
by this encoder.encode
in class MessageToByteEncoder<ByteBuf>
ctx
- the ChannelHandlerContext
which this MessageToByteEncoder
belongs toin
- the message to encodeout
- the ByteBuf
into which the encoded message will be writtenException
- is thrown if an error accourpublic boolean isClosed()
true
if and only if the compressed stream has been finished.public ChannelFuture close()
Lz4FrameEncoder
and so finish the encoding.
The returned ChannelFuture
will be notified once the operation completes.public ChannelFuture close(ChannelPromise promise)
Lz4FrameEncoder
and so finish the encoding.
The given ChannelFuture
will be notified once the operation
completes and will also be returned.public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.close(ChannelPromise)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.close
in interface ChannelHandler
close
in class ChannelHandlerAdapter
ctx
- the ChannelHandlerContext
for which the close operation is madepromise
- the ChannelPromise
to notify once the operation completesException
- thrown if an error accourpublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
Exception
Copyright © 2008–2015 The Netty Project. All rights reserved.