- java.lang.Object
-
- io.netty5.handler.codec.compression.Lz4Decompressor
-
- All Implemented Interfaces:
Decompressor
,AutoCloseable
public final class Lz4Decompressor extends Object implements Decompressor
Uncompresses aBuffer
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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the decompressor.Buffer
decompress(Buffer in, BufferAllocator allocator)
This method will read from the inputBuffer
and decompress into a newBuffer
that will be allocated (if needed) from theBufferAllocator
.boolean
isClosed()
Returntrue
if the decompressor was closed,false
otherwise.boolean
isFinished()
Returns true if the decompressor was finish.static Supplier<Lz4Decompressor>
newFactory()
Creates the fastest LZ4 decompressor factory.static Supplier<Lz4Decompressor>
newFactory(boolean validateChecksums)
Creates a LZ4 decompressor factory with fastest decoder instance available on your machine.static Supplier<Lz4Decompressor>
newFactory(net.jpountz.lz4.LZ4Factory factory, boolean validateChecksums)
Creates a LZ4 decompressor factory with customizable implementation.static Supplier<Lz4Decompressor>
newFactory(net.jpountz.lz4.LZ4Factory factory, Checksum checksum)
Creates a customizable LZ4 decompressor factory.
-
-
-
Method Detail
-
newFactory
public static Supplier<Lz4Decompressor> newFactory()
Creates the fastest LZ4 decompressor factory. 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 thenewFactory(boolean)
constructor with the argument set totrue
.- Returns:
- the factory.
-
newFactory
public static Supplier<Lz4Decompressor> newFactory(boolean validateChecksums)
Creates a LZ4 decompressor factory 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 suitableDecompressionException
will be thrown- Returns:
- the factory.
-
newFactory
public static Supplier<Lz4Decompressor> newFactory(net.jpountz.lz4.LZ4Factory factory, boolean validateChecksums)
Creates a LZ4 decompressor factory with customizable implementation.- Parameters:
factory
- user customizableLZ4Factory
instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafe
validateChecksums
- iftrue
, the checksum field will be validated against the actual uncompressed data, and if the checksums do not match, a suitableDecompressionException
will be thrown. In this case encoder will use xxhash hashing for Java, based on Yann Collet's work available at Github.- Returns:
- the factory.
-
newFactory
public static Supplier<Lz4Decompressor> newFactory(net.jpountz.lz4.LZ4Factory factory, Checksum checksum)
Creates a customizable LZ4 decompressor factory.- Parameters:
factory
- user customizableLZ4Factory
instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses theUnsafe
checksum
- theChecksum
instance to use to check data for integrity. You may setnull
if you do not want to validate checksum of each block- Returns:
- the factory.
-
decompress
public Buffer decompress(Buffer in, BufferAllocator allocator) throws DecompressionException
Description copied from interface:Decompressor
This method will read from the inputBuffer
and decompress into a newBuffer
that will be allocated (if needed) from theBufferAllocator
. If there is not enough readable data in theBuffer
to process it will returnnull
. This method should be called in a loop as long:Decompressor.isFinished()
isfalse
- something was read from the
input
- something was returned
- Specified by:
decompress
in interfaceDecompressor
- Parameters:
in
- theBuffer
that contains the data to be decompressed.allocator
- theBufferAllocator
that is used to allocate a new buffer (if needed) to write the decompressed bytes too.- Returns:
- the
Buffer
that contains the decompressed data. The caller of this method takes ownership of the buffer. The return value will benull
if there is not enough data readable in the input to make any progress. In this case the user should call it again once there is more data ready to be consumed. - Throws:
DecompressionException
- thrown if an decompression error was encountered or the decompressor was closed before.
-
isFinished
public boolean isFinished()
Description copied from interface:Decompressor
Returns true if the decompressor was finish. This might be because the decompressor was explicitly closed or the end of the compressed stream was detected.- Specified by:
isFinished
in interfaceDecompressor
- Returns:
true
if the decompressor is done with decompressing the stream.
-
isClosed
public boolean isClosed()
Description copied from interface:Decompressor
Returntrue
if the decompressor was closed,false
otherwise.- Specified by:
isClosed
in interfaceDecompressor
- Returns:
- if
Decompressor.close()
was called.
-
close
public void close()
Description copied from interface:Decompressor
Close the decompressor. After this method was calledDecompressor.isFinished()
will returntrue
as well and it is not allowed to callDecompressor.decompress(Buffer, BufferAllocator)
anymore.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDecompressor
-
-