Class Lz4FrameDecoder
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.ByteToMessageDecoder
io.netty.handler.codec.compression.Lz4FrameDecoder
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler
Uncompresses a
ByteBuf encoded with 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 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumCurrent state of stream.Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.CumulatorNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intType of current block.private ByteBufChecksumUnderlying checksum calculator in use.private intCompressed length of current incoming block.private intChecksum value of current incoming block.private Lz4FrameDecoder.Stateprivate intDecompressed length of current incoming block.private net.jpountz.lz4.LZ4FastDecompressorUnderlying decompressor in use.private final intFields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR -
Constructor Summary
ConstructorsConstructorDescriptionCreates the fastest LZ4 decoder.Lz4FrameDecoder(boolean validateChecksums) Creates a LZ4 decoder with fastest decoder instance available on your machine.Lz4FrameDecoder(boolean validateChecksums, int maxDecompressedLength) Creates a LZ4 decoder with fastest decoder instance available on your machine.Lz4FrameDecoder(net.jpountz.lz4.LZ4Factory factory, boolean validateChecksums) Creates a new LZ4 decoder with customizable implementation.Lz4FrameDecoder(net.jpountz.lz4.LZ4Factory factory, Checksum checksum) Creates a new customizable LZ4 decoder.Lz4FrameDecoder(net.jpountz.lz4.LZ4Factory factory, Checksum checksum, int maxDecompressedLength) Creates a new customizable LZ4 decoder. -
Method Summary
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
-
Field Details
-
maxDecompressedLength
private final int maxDecompressedLength -
currentState
-
decompressor
private net.jpountz.lz4.LZ4FastDecompressor decompressorUnderlying decompressor in use. -
checksum
Underlying checksum calculator in use. -
blockType
private int blockTypeType of current block. -
compressedLength
private int compressedLengthCompressed length of current incoming block. -
decompressedLength
private int decompressedLengthDecompressed length of current incoming block. -
currentChecksum
private int currentChecksumChecksum value of current incoming block.
-
-
Constructor Details
-
Lz4FrameDecoder
public Lz4FrameDecoder()Creates the fastest LZ4 decoder. Note that by default, validation of the checksum header in each chunk is DISABLED for performance improvements. If performance is less of an issue, or if you would prefer the safety that checksum validation brings, please use theLz4FrameDecoder(boolean)constructor with the argument set totrue. -
Lz4FrameDecoder
public Lz4FrameDecoder(boolean validateChecksums) Creates a LZ4 decoder with fastest decoder instance available on your machine.- Parameters:
validateChecksums- iftrue, the checksum field will be validated against the actual uncompressed data, and if the checksums do not match, a suitableDecompressionExceptionwill be thrown
-
Lz4FrameDecoder
public Lz4FrameDecoder(boolean validateChecksums, int maxDecompressedLength) Creates a LZ4 decoder with fastest decoder instance available on your machine.- Parameters:
validateChecksums- iftrue, the checksum field will be validated against the actual uncompressed data, and if the checksums do not match, a suitableDecompressionExceptionwill be thrownmaxDecompressedLength- maximum length of the decompressed block. If0is given it uses32MBby default.
-
Lz4FrameDecoder
public Lz4FrameDecoder(net.jpountz.lz4.LZ4Factory factory, boolean validateChecksums) Creates a new LZ4 decoder with customizable implementation.- Parameters:
factory- user customizableLZ4Factoryinstance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafevalidateChecksums- iftrue, the checksum field will be validated against the actual uncompressed data, and if the checksums do not match, a suitableDecompressionExceptionwill be thrown. In this case encoder will use xxhash hashing for Java, based on Yann Collet's work available at Github.
-
Lz4FrameDecoder
Creates a new customizable LZ4 decoder.- Parameters:
factory- user customizableLZ4Factoryinstance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafechecksum- theChecksuminstance to use to check data for integrity. You may setnullif you do not want to validate checksum of each block
-
Lz4FrameDecoder
public Lz4FrameDecoder(net.jpountz.lz4.LZ4Factory factory, Checksum checksum, int maxDecompressedLength) Creates a new customizable LZ4 decoder.- Parameters:
factory- user customizableLZ4Factoryinstance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafechecksum- theChecksuminstance to use to check data for integrity. You may setnullif you do not want to validate checksum of each blockmaxDecompressedLength- maximum length of the decompressed block. If0is given it uses32MBby default.
-
-
Method Details
-
decode
Description copied from class:ByteToMessageDecoderDecode the from oneByteBufto an other. This method will be called till either the inputByteBufhas nothing to read when return from this method or till nothing was read from the inputByteBuf.- Specified by:
decodein classByteToMessageDecoder- Parameters:
ctx- theChannelHandlerContextwhich thisByteToMessageDecoderbelongs toin- theByteBuffrom which to read dataout- theListto which decoded messages should be added- Throws:
Exception- is thrown if an error occurs
-
isClosed
public boolean isClosed()Returnstrueif and only if the end of the compressed stream has been reached.
-