- java.lang.Object
-
- io.netty5.handler.codec.compression.ZlibDecompressor
-
- All Implemented Interfaces:
Decompressor
,AutoCloseable
public final class ZlibDecompressor extends Object implements Decompressor
Decompress aBuffer
using the inflate algorithm.
-
-
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
.protected void
decompressionBufferExhausted(Buffer buffer)
boolean
isClosed()
Returntrue
if the decompressor was closed,false
otherwise.boolean
isFinished()
Returns true if the decompressor was finish.static Supplier<ZlibDecompressor>
newFactory()
Creates a zlib decompressor factory with the default wrapper (ZlibWrapper.ZLIB
).static Supplier<ZlibDecompressor>
newFactory(boolean decompressConcatenated)
static Supplier<ZlibDecompressor>
newFactory(boolean decompressConcatenated, int maxAllocation)
static Supplier<ZlibDecompressor>
newFactory(byte[] dictionary)
Creates a zlib decompressor factory with the specified preset dictionary.static Supplier<ZlibDecompressor>
newFactory(byte[] dictionary, int maxAllocation)
Creates zlib decompressor factory with the specified preset dictionary and maximum buffer allocation.static Supplier<ZlibDecompressor>
newFactory(int maxAllocation)
Creates a zlib decompressor factory with the default wrapper (ZlibWrapper.ZLIB
) and the specified maximum buffer allocation.static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper)
Creates zlib decompressor factory with the specified wrapper.static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, boolean decompressConcatenated)
static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, boolean decompressConcatenated, int maxAllocation)
static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, int maxAllocation)
Creates zlib decompressor factory with the specified wrapper and maximum buffer allocation.protected Buffer
prepareDecompressBuffer(BufferAllocator allocator, Buffer buffer, int preferredSize)
Allocate or expand the decompression buffer, without exceeding the maximum allocation.
-
-
-
Method Detail
-
newFactory
public static Supplier<ZlibDecompressor> newFactory()
Creates a zlib decompressor factory with the default wrapper (ZlibWrapper.ZLIB
).- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(int maxAllocation)
Creates a zlib decompressor factory with the default wrapper (ZlibWrapper.ZLIB
) and the specified maximum buffer allocation.- Parameters:
maxAllocation
- Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by theBufferAllocator
.- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(byte[] dictionary)
Creates a zlib decompressor factory with the specified preset dictionary. The wrapper is alwaysZlibWrapper.ZLIB
because it is the only format that supports the preset dictionary.- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(byte[] dictionary, int maxAllocation)
Creates zlib decompressor factory with the specified preset dictionary and maximum buffer allocation. The wrapper is alwaysZlibWrapper.ZLIB
because it is the only format that supports the preset dictionary.- Parameters:
maxAllocation
- Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by theBufferAllocator
.- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper)
Creates zlib decompressor factory with the specified wrapper. Be aware that onlyZlibWrapper.GZIP
,ZlibWrapper.ZLIB
andZlibWrapper.NONE
are supported atm.- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, int maxAllocation)
Creates zlib decompressor factory with the specified wrapper and maximum buffer allocation. Be aware that onlyZlibWrapper.GZIP
,ZlibWrapper.ZLIB
andZlibWrapper.NONE
are supported atm.- Parameters:
maxAllocation
- Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by theBufferAllocator
.- Returns:
- the factory.
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, boolean decompressConcatenated)
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, boolean decompressConcatenated, int maxAllocation)
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(boolean decompressConcatenated)
-
newFactory
public static Supplier<ZlibDecompressor> newFactory(boolean decompressConcatenated, int maxAllocation)
-
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.
-
prepareDecompressBuffer
protected Buffer prepareDecompressBuffer(BufferAllocator allocator, Buffer buffer, int preferredSize)
Allocate or expand the decompression buffer, without exceeding the maximum allocation. CallsdecompressionBufferExhausted(Buffer)
if the buffer is full and cannot be expanded further.
-
decompressionBufferExhausted
protected void decompressionBufferExhausted(Buffer buffer)
-
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.
-
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
-
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.
-
-