public class Lz4FrameEncoder extends MessageToByteEncoder<io.netty.buffer.ByteBuf>
ByteBuf
using the LZ4 format.
See original LZ4 Github project
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 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *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
Github.
|
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
Github.
|
Lz4FrameEncoder(net.jpountz.lz4.LZ4Factory factory,
boolean highCompressor,
int blockSize,
Checksum checksum)
Creates a new customizable LZ4 encoder.
|
Lz4FrameEncoder(net.jpountz.lz4.LZ4Factory factory,
boolean highCompressor,
int blockSize,
Checksum checksum,
int maxEncodeSize)
Creates a new customizable LZ4 encoder.
|
Modifier and Type | Method and Description |
---|---|
protected io.netty.buffer.ByteBuf |
allocateBuffer(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf) . |
io.netty.channel.ChannelFuture |
close()
Close this
Lz4FrameEncoder and so finish the encoding. |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
io.netty.channel.ChannelFuture |
close(io.netty.channel.ChannelPromise promise)
Close this
Lz4FrameEncoder and so finish the encoding. |
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out)
Encode a message into a
ByteBuf . |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
boolean |
isClosed()
Returns
true if and only if the compressed stream has been finished. |
acceptOutboundMessage, isPreferDirect, write
bind, connect, deregister, disconnect, read
ensureNotSharable, exceptionCaught, isSharable
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(net.jpountz.lz4.LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum)
factory
- user customizable 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 integritypublic Lz4FrameEncoder(net.jpountz.lz4.LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum, int maxEncodeSize)
factory
- user customizable 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 integritymaxEncodeSize
- the maximum size for an encode (compressed) bufferprotected io.netty.buffer.ByteBuf allocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)
MessageToByteEncoder
ByteBuf
which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf)
.
Sub-classes may override this method to return ByteBuf
with a perfect matching initialCapacity
.allocateBuffer
in class MessageToByteEncoder<io.netty.buffer.ByteBuf>
protected void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.ByteBuf out) throws Exception
ByteBuf
. This method will be called for each written message that can be handled
by this encoder.
Encodes the input buffer into blockSize
chunks in the output buffer. Data is only compressed and
written once we hit the blockSize
; else, it is copied into the backing buffer
to await
more data.encode
in class MessageToByteEncoder<io.netty.buffer.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 occurspublic void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception
flush
in interface io.netty.channel.ChannelOutboundHandler
flush
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public boolean isClosed()
true
if and only if the compressed stream has been finished.public io.netty.channel.ChannelFuture close()
Lz4FrameEncoder
and so finish the encoding.
The returned ChannelFuture
will be notified once the operation completes.public io.netty.channel.ChannelFuture close(io.netty.channel.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(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
close
in interface io.netty.channel.ChannelOutboundHandler
close
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Copyright © 2008–2019 The Netty Project. All rights reserved.