Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.compression

public final Class ZlibDecompressor

extends Object
implements Decompressor
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.compression.Decompressor, java.lang.AutoCloseable
Imports
io.netty5.buffer.Buffer, .BufferAllocator, java.nio.ByteBuffer, java.util.function.Supplier, java.util.zip.CRC32, .DataFormatException, .Deflater, .Inflater

Decompress a Buffer using the inflate algorithm.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private boolean
private final BufferChecksum
private boolean
private final boolean
private final byte[]
private static final int
private static final int
private static final int
private boolean
private int
private static final int
private static final int
private ZlibDecompressor.GzipState
private Inflater
private final int
maxAllocation

Maximum allowed size of the decompression buffer.

private int

Constructor Summary

AccessConstructor and Description
private
ZlibDecompressor(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated, int maxAllocation)

Method Summary

Modifier and TypeMethod and Description
public void
public Buffer
decompress(Buffer
the Buffer that contains the data to be decompressed.
in
,
BufferAllocator
the BufferAllocator that is used to allocate a new buffer (if needed) to write the decompressed bytes too.
allocator
)

Implements io.netty5.handler.codec.compression.Decompressor.decompress.

This method will read from the input Buffer and decompress into a new Buffer that will be allocated (if needed) from the BufferAllocator.
protected void
private boolean
public boolean
isClosed()

Implements io.netty5.handler.codec.compression.Decompressor.isClosed.

Return true if the decompressor was closed, false otherwise.
public boolean
isFinished()

Implements io.netty5.handler.codec.compression.Decompressor.isFinished.

Returns true if the decompressor was finish.
private static boolean
looksLikeZlib(short cmf_flg)

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
()

Creates a zlib decompressor factory with the default wrapper (ZlibWrapper#ZLIB).

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
(int
Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.
maxAllocation
)

Creates a zlib decompressor factory with the default wrapper (ZlibWrapper#ZLIB) and the specified maximum buffer allocation.

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
(byte[] dictionary)

Creates a zlib decompressor factory with the specified preset dictionary.

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
(byte[] dictionary, int
Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.
maxAllocation
)

Creates zlib decompressor factory with the specified preset dictionary and maximum buffer allocation.

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
(ZlibWrapper wrapper)

Creates zlib decompressor factory with the specified wrapper.

public static Supplier<ZlibDecompressor>

Returns:

the factory.
newFactory
(ZlibWrapper wrapper, int
Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.
maxAllocation
)

Creates zlib decompressor factory with the specified wrapper and maximum buffer allocation.

public static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, boolean decompressConcatenated)

public static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, boolean decompressConcatenated, int maxAllocation)

public static Supplier<ZlibDecompressor>
newFactory(boolean decompressConcatenated)

public static Supplier<ZlibDecompressor>
newFactory(boolean decompressConcatenated, int maxAllocation)

private static Supplier<ZlibDecompressor>
newFactory(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated, int maxAllocation)

protected Buffer
prepareDecompressBuffer(BufferAllocator allocator, Buffer buffer, int preferredSize)

Allocate or expand the decompression buffer, without exceeding the maximum allocation.

private boolean

Returns:

true if the footer could be read, false if the read could not be performed as the input Buffer doesn't have enough readable bytes (8 bytes).
readGZIPFooter
(Buffer
the input.
in
)

Read the GZIP footer.

private boolean
private boolean

Returns:

true if the operation is complete and we can move to the next state, false if we need to retry again once we have more readable bytes.
skipIfNeeded
(Buffer
the input
in
,
int
the mask that should be present in the flags when we need to skip bytes.
flagMask
)

Skip bytes in the input if needed until we find the end marker 0x00.

private boolean

Returns:

true if verification could be performed, false if verification could not be performed as the input Buffer doesn't have enough readable bytes (4 bytes).
verifyCrc
(Buffer
the input.
in
)

Verifies CRC.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
crcback to summary
private final BufferChecksum crc
decideZlibOrNoneback to summary
private boolean decideZlibOrNone
decompressConcatenatedback to summary
private final boolean decompressConcatenated
dictionaryback to summary
private final byte[] dictionary
FCOMMENTback to summary
private static final int FCOMMENT
FEXTRAback to summary
private static final int FEXTRA
FHCRCback to summary
private static final int FHCRC
finishedback to summary
private boolean finished
flagsback to summary
private int flags
FNAMEback to summary
private static final int FNAME
FRESERVEDback to summary
private static final int FRESERVED
gzipStateback to summary
private ZlibDecompressor.GzipState gzipState
inflaterback to summary
private Inflater inflater
maxAllocationback to summary
private final int maxAllocation

Maximum allowed size of the decompression buffer.

xlenback to summary
private int xlen

Constructor Detail

ZlibDecompressorback to summary
private ZlibDecompressor(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated, int maxAllocation)

Method Detail

closeback to summary
public void close()

Implements io.netty5.handler.codec.compression.Decompressor.close.

Doc from io.netty5.handler.codec.compression.Decompressor.close.

Close the decompressor. After this method was called isFinished() will return true as well and it is not allowed to call decompress(Buffer, BufferAllocator) anymore.

Annotations
@Override
decompressback to summary
public Buffer decompress(Buffer in, BufferAllocator allocator) throws DecompressionException

Implements io.netty5.handler.codec.compression.Decompressor.decompress.

Doc from io.netty5.handler.codec.compression.Decompressor.decompress.

This method will read from the input Buffer and decompress into a new Buffer that will be allocated (if needed) from the BufferAllocator. If there is not enough readable data in the Buffer to process it will return null. This method should be called in a loop as long:

    • something was read from the input
      something was returned
  • Otherwise this method should be called again once there is more data in the input buffer.
    Parameters
    in:Buffer

    the Buffer that contains the data to be decompressed.

    allocator:BufferAllocator

    the BufferAllocator that is used to allocate a new buffer (if needed) to write the decompressed bytes too.

    Returns:Buffer

    the Buffer that contains the decompressed data. The caller of this method takes ownership of the buffer. The return value will be null 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.

    Annotations
    @Override
    Exceptions
    DecompressionException:
    thrown if an decompression error was encountered or the decompressor was closed before.
    decompressionBufferExhaustedback to summary
    protected void decompressionBufferExhausted(Buffer buffer)
    handleGzipFooterback to summary
    private boolean handleGzipFooter(Buffer in)
    isClosedback to summary
    public boolean isClosed()

    Implements io.netty5.handler.codec.compression.Decompressor.isClosed.

    Doc from io.netty5.handler.codec.compression.Decompressor.isClosed.

    Return true if the decompressor was closed, false otherwise.

    Returns:boolean

    if close() was called.

    Annotations
    @Override
    isFinishedback to summary
    public boolean isFinished()

    Implements io.netty5.handler.codec.compression.Decompressor.isFinished.

    Doc from io.netty5.handler.codec.compression.Decompressor.isFinished.

    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.

    Returns:boolean

    true if the decompressor is done with decompressing the stream.

    Annotations
    @Override
    looksLikeZlibback to summary
    private static boolean looksLikeZlib(short cmf_flg)
    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory()

    Creates a zlib decompressor factory with the default wrapper (ZlibWrapper#ZLIB).

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    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:int

    Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(byte[] dictionary)

    Creates a zlib decompressor factory with the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    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 always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

    Parameters
    maxAllocation:int

    Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper)

    Creates zlib decompressor factory with the specified wrapper. Be aware that only ZlibWrapper#GZIP, ZlibWrapper#ZLIB and ZlibWrapper#NONE are supported atm.

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, int maxAllocation)

    Creates zlib decompressor factory with the specified wrapper and maximum buffer allocation. Be aware that only ZlibWrapper#GZIP, ZlibWrapper#ZLIB and ZlibWrapper#NONE are supported atm.

    Parameters
    maxAllocation:int

    Maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is decided by the BufferAllocator.

    Returns:Supplier<ZlibDecompressor>

    the factory.

    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, boolean decompressConcatenated)
    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, boolean decompressConcatenated, int maxAllocation)
    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(boolean decompressConcatenated)
    newFactoryback to summary
    public static Supplier<ZlibDecompressor> newFactory(boolean decompressConcatenated, int maxAllocation)
    newFactoryback to summary
    private static Supplier<ZlibDecompressor> newFactory(ZlibWrapper wrapper, byte[] dictionary, boolean decompressConcatenated, int maxAllocation)
    prepareDecompressBufferback to summary
    protected Buffer prepareDecompressBuffer(BufferAllocator allocator, Buffer buffer, int preferredSize)

    Allocate or expand the decompression buffer, without exceeding the maximum allocation. Calls decompressionBufferExhausted(Buffer) if the buffer is full and cannot be expanded further.

    readGZIPFooterback to summary
    private boolean readGZIPFooter(Buffer in)

    Read the GZIP footer.

    Parameters
    in:Buffer

    the input.

    Returns:boolean

    true if the footer could be read, false if the read could not be performed as the input Buffer doesn't have enough readable bytes (8 bytes).

    readGZIPHeaderback to summary
    private boolean readGZIPHeader(Buffer in)
    skipIfNeededback to summary
    private boolean skipIfNeeded(Buffer in, int flagMask)

    Skip bytes in the input if needed until we find the end marker 0x00.

    Parameters
    in:Buffer

    the input

    flagMask:int

    the mask that should be present in the flags when we need to skip bytes.

    Returns:boolean

    true if the operation is complete and we can move to the next state, false if we need to retry again once we have more readable bytes.

    verifyCrcback to summary
    private boolean verifyCrc(Buffer in)

    Verifies CRC.

    Parameters
    in:Buffer

    the input.

    Returns:boolean

    true if verification could be performed, false if verification could not be performed as the input Buffer doesn't have enough readable bytes (4 bytes).

    verifyCrc16back to summary
    private boolean verifyCrc16(Buffer in)
    io.netty5.handler.codec.compression back to summary

    private final Enum ZlibDecompressor.GzipState

    extends Enum<ZlibDecompressor.GzipState>
    Class Inheritance

    Field Summary

    Modifier and TypeField and Description
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState
    public static final ZlibDecompressor.GzipState

    Constructor Summary

    AccessConstructor and Description
    private

    Method Summary

    Modifier and TypeMethod and Description
    public static ZlibDecompressor.GzipState
    public static ZlibDecompressor.GzipState[]
    Inherited from java.lang.Enum:
    clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

    Field Detail

    FLG_READback to summary
    public static final ZlibDecompressor.GzipState FLG_READ
    FOOTER_STARTback to summary
    public static final ZlibDecompressor.GzipState FOOTER_START
    HEADER_ENDback to summary
    public static final ZlibDecompressor.GzipState HEADER_END
    HEADER_STARTback to summary
    public static final ZlibDecompressor.GzipState HEADER_START
    PROCESS_FHCRCback to summary
    public static final ZlibDecompressor.GzipState PROCESS_FHCRC
    SKIP_COMMENTback to summary
    public static final ZlibDecompressor.GzipState SKIP_COMMENT
    SKIP_FNAMEback to summary
    public static final ZlibDecompressor.GzipState SKIP_FNAME
    XLEN_READback to summary
    public static final ZlibDecompressor.GzipState XLEN_READ

    Constructor Detail

    GzipStateback to summary
    private GzipState()

    Method Detail

    valueOfback to summary
    public static ZlibDecompressor.GzipState valueOf(String name)
    valuesback to summary
    public static ZlibDecompressor.GzipState[] values()