- java.lang.Object
-
- io.netty5.handler.codec.compression.LzfDecompressor
-
- All Implemented Interfaces:
Decompressor
,AutoCloseable
public final class LzfDecompressor extends Object implements Decompressor
Uncompresses aBuffer
encoded with the LZF format. See original LZF package and LZF format for full description.
-
-
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<LzfDecompressor>
newFactory()
Creates a new LZF decompressor factory with the most optimal available methods for underlying data access.static Supplier<LzfDecompressor>
newFactory(boolean safeInstance)
Creates a new LZF decompressor factory with specified decoding instance.
-
-
-
Method Detail
-
newFactory
public static Supplier<LzfDecompressor> newFactory()
Creates a new LZF decompressor factory with the most optimal available methods for underlying data access. It will "unsafe" instance if one can be used on current JVM. It should be safe to call this constructor as implementations are dynamically loaded; however, on some non-standard platforms it may be necessary to useLzfDecompressor(boolean)
withtrue
param.- Returns:
- the factory.
-
newFactory
public static Supplier<LzfDecompressor> newFactory(boolean safeInstance)
Creates a new LZF decompressor factory with specified decoding instance.- Parameters:
safeInstance
- Iftrue
decoder will useChunkDecoder
that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise decoder will try to use highly optimizedChunkDecoder
implementation that uses Sun JDK'sUnsafe
class (which may be included by other JDK's as well).- 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
-
-