Class Lz4FrameEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
-
- io.netty.handler.codec.compression.Lz4FrameEncoder
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelOutboundHandler
public class Lz4FrameEncoder extends io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>Compresses aByteBufusing 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 Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected io.netty.buffer.ByteBufallocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)io.netty.channel.ChannelFutureclose()Close thisLz4FrameEncoderand so finish the encoding.voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)io.netty.channel.ChannelFutureclose(io.netty.channel.ChannelPromise promise)Close thisLz4FrameEncoderand so finish the encoding.protected voidencode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.ByteBuf out)Encodes the input buffer intoblockSizechunks in the output buffer.voidflush(io.netty.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)booleanisClosed()Returnstrueif and only if the compressed stream has been finished.-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, isPreferDirect, write
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, connect, deregister, disconnect, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, isSharable
-
-
-
-
Constructor Detail
-
Lz4FrameEncoder
public 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
public 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.- Parameters:
highCompressor- iftruecodec will use compressor which requires more memory and is slower but compresses more efficiently
-
Lz4FrameEncoder
public Lz4FrameEncoder(net.jpountz.lz4.LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum)Creates a new customizable LZ4 encoder.- Parameters:
factory- user customizableLZ4Factoryinstance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafehighCompressor- iftruecodec 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- theChecksuminstance to use to check data for integrity
-
Lz4FrameEncoder
public Lz4FrameEncoder(net.jpountz.lz4.LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum, int maxEncodeSize)Creates a new customizable LZ4 encoder.- Parameters:
factory- user customizableLZ4Factoryinstance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafehighCompressor- iftruecodec 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- theChecksuminstance to use to check data for integritymaxEncodeSize- the maximum size for an encode (compressed) buffer
-
-
Method Detail
-
allocateBuffer
protected io.netty.buffer.ByteBuf allocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)- Overrides:
allocateBufferin classio.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
-
encode
protected void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.ByteBuf out) throws ExceptionEncodes the input buffer intoblockSizechunks in the output buffer. Data is only compressed and written once we hit theblockSize; else, it is copied into the backingbufferto await more data.- Specified by:
encodein classio.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>- Throws:
Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
isClosed
public boolean isClosed()
Returnstrueif and only if the compressed stream has been finished.
-
close
public io.netty.channel.ChannelFuture close()
Close thisLz4FrameEncoderand so finish the encoding. The returnedChannelFuturewill be notified once the operation completes.
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.ChannelPromise promise)
Close thisLz4FrameEncoderand so finish the encoding. The givenChannelFuturewill be notified once the operation completes and will also be returned.
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter
-
-