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

public final Class ZlibCompressor

extends Object
implements Compressor
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.compression.Compressor, java.lang.AutoCloseable
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.util.internal.EmptyArrays, .SystemPropertyUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.nio.ByteBuffer, java.util.function.Supplier, java.util.zip.CRC32, .Deflater

Compresses a Buffer using the deflate algorithm.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final CRC32
private final Deflater
private static final byte[]
private static final InternalLogger
private static final int
MAX_INITIAL_OUTPUT_BUFFER_SIZE

Maximum initial size for temporary heap buffers used for the compressed output.

private ZlibCompressor.State
private final ZlibWrapper
private boolean

Constructor Summary

AccessConstructor and Description
private
ZlibCompressor(ZlibWrapper wrapper, int compressionLevel)

private
ZlibCompressor(int compressionLevel, byte[] dictionary)

Method Summary

Modifier and TypeMethod and Description
public void
close()

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

# Close the compressor.
public Buffer
compress(Buffer
the Buffer that contains the data to be compressed.
uncompressed
,
BufferAllocator
the BufferAllocator that is used to allocate a new buffer (if needed) to write the compressed bytes too.
allocator
)

Implements io.netty5.handler.codec.compression.Compressor.compress.

This method will read from the input Buffer and compress into a new Buffer that will be allocated (if needed) from the BufferAllocator.
private Buffer
compressData(Buffer uncompressed, BufferAllocator allocator)

private void
private void
public Buffer
finish(BufferAllocator allocator)

Implements io.netty5.handler.codec.compression.Compressor.finish.

By calling this method we signal that the compression stream is marked as finish.
public boolean
isClosed()

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

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

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

Returns true if the compressor was finished or closed.
public static Supplier<ZlibCompressor>

Returns:

the factory.
newFactory
()

Creates a zlib compressor factory with the default compression level (6) and the default wrapper (ZlibWrapper#ZLIB).

public static Supplier<ZlibCompressor>
newFactory(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a zlib compressor factory with the specified compressionLevel and the default wrapper (ZlibWrapper#ZLIB).

public static Supplier<ZlibCompressor>

Returns:

the factory.
newFactory
(ZlibWrapper wrapper)

Creates a zlib compressor factory with the default compression level (6) and the specified wrapper.

public static Supplier<ZlibCompressor>

Returns:

the factory.
newFactory
(ZlibWrapper wrapper, int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a zlib compressor factory with the specified compressionLevel and the specified wrapper.

public static Supplier<ZlibCompressor>

Returns:

the factory.
newFactory
(byte[]
the preset dictionary
dictionary
)

Creates a zlib compressor factory with the default compression level (6) and the specified preset dictionary.

public static Supplier<ZlibCompressor>

Returns:

the factory.
newFactory
(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
,
byte[]
the preset dictionary
dictionary
)

Creates a zlib compressor factory with the specified compressionLevel and the specified preset dictionary.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

crcback to summary
private final CRC32 crc
deflaterback to summary
private final Deflater deflater
gzipHeaderback to summary
private static final byte[] gzipHeader
loggerback to summary
private static final InternalLogger logger
MAX_INITIAL_OUTPUT_BUFFER_SIZEback to summary
private static final int MAX_INITIAL_OUTPUT_BUFFER_SIZE

Maximum initial size for temporary heap buffers used for the compressed output. Buffer may still grow beyond this if necessary.

stateback to summary
private ZlibCompressor.State state
wrapperback to summary
private final ZlibWrapper wrapper
writeHeaderback to summary
private boolean writeHeader

Constructor Detail

ZlibCompressorback to summary
private ZlibCompressor(ZlibWrapper wrapper, int compressionLevel)
ZlibCompressorback to summary
private ZlibCompressor(int compressionLevel, byte[] dictionary)

Method Detail

closeback to summary
public void close()

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

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

# Close the compressor. After this method was called isFinished() will return true as well and it is not allowed to call compress(Buffer, BufferAllocator) or finish(BufferAllocator) anymore -

Annotations
@Override
compressback to summary
public Buffer compress(Buffer uncompressed, BufferAllocator allocator) throws CompressionException

Implements io.netty5.handler.codec.compression.Compressor.compress.

Doc from io.netty5.handler.codec.compression.Compressor.compress.

This method will read from the input Buffer and compress into a new Buffer that will be allocated (if needed) from the BufferAllocator. This method is expected to consume all data from the input but not take ownership. The caller is responsible to release the input buffer after this method returns.

Parameters
uncompressed:Buffer

the Buffer that contains the data to be compressed.

allocator:BufferAllocator

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

Returns:Buffer

the Buffer that contains the compressed data. The caller of this method takes ownership of the buffer. The return value will never be null.

Annotations
@Override
Exceptions
CompressionException:
thrown if an compression error was encountered or the compressor was closed already.
compressDataback to summary
private Buffer compressData(Buffer uncompressed, BufferAllocator allocator)
compressDataback to summary
private void compressData(ByteBuffer in, Buffer out)
deflateback to summary
private void deflate(Buffer out)
finishback to summary
public Buffer finish(BufferAllocator allocator)

Implements io.netty5.handler.codec.compression.Compressor.finish.

Doc from io.netty5.handler.codec.compression.Compressor.finish.

By calling this method we signal that the compression stream is marked as finish. The returned Buffer might contain a "trailer" which marks the end of the stream.

Returns:Buffer

the Buffer which represent the end of the compression stream, which might be empty if the compressor don't need a trailer to signal the end. The caller of this method takes ownership of the buffer. The return value will never be null.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

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

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

Return true if the decompressor was closed, false otherwise.

Returns:boolean

true if the decompressor was closed, false otherwise.

Annotations
@Override
isFinishedback to summary
public boolean isFinished()

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

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

Returns true if the compressor was finished or closed. This might happen because someone explicit called finish(BufferAllocator) / close() or the compressor implementation did decide to close itself due a compression error which can't be recovered. After isFinished() returns true the compress(Buffer, BufferAllocator) method will just return an empty buffer without consuming anything from its input buffer.

Returns:boolean

true if the compressor was marked as finished, false otherwise.

Annotations
@Override
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory()

Creates a zlib compressor factory with the default compression level (6) and the default wrapper (ZlibWrapper#ZLIB).

Returns:Supplier<ZlibCompressor>

the factory.

Exceptions
CompressionException:
if failed to initialize zlib
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory(int compressionLevel)

Creates a zlib compressor factory with the specified compressionLevel and the default wrapper (ZlibWrapper#ZLIB).

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Exceptions
CompressionException:
if failed to initialize zlib
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory(ZlibWrapper wrapper)

Creates a zlib compressor factory with the default compression level (6) and the specified wrapper.

Returns:Supplier<ZlibCompressor>

the factory.

Exceptions
CompressionException:
if failed to initialize zlib
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory(ZlibWrapper wrapper, int compressionLevel)

Creates a zlib compressor factory with the specified compressionLevel and the specified wrapper.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Returns:Supplier<ZlibCompressor>

the factory.

Exceptions
CompressionException:
if failed to initialize zlib
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory(byte[] dictionary)

Creates a zlib compressor factory with the default compression level (6) and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
dictionary:byte[]

the preset dictionary

Returns:Supplier<ZlibCompressor>

the factory.

Exceptions
CompressionException:
if failed to initialize zlib
newFactoryback to summary
public static Supplier<ZlibCompressor> newFactory(int compressionLevel, byte[] dictionary)

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

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

dictionary:byte[]

the preset dictionary

Returns:Supplier<ZlibCompressor>

the factory.

Exceptions
CompressionException:
if failed to initialize zlib
io.netty5.handler.codec.compression back to summary

private final Enum ZlibCompressor.State

extends Enum<ZlibCompressor.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ZlibCompressor.State
public static final ZlibCompressor.State
public static final ZlibCompressor.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CLOSEDback to summary
public static final ZlibCompressor.State CLOSED
FINISHEDback to summary
public static final ZlibCompressor.State FINISHED
PROCESSINGback to summary
public static final ZlibCompressor.State PROCESSING

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static ZlibCompressor.State valueOf(String name)
valuesback to summary
public static ZlibCompressor.State[] values()