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

public final Class Lz4Compressor

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.handler.codec.EncoderException, io.netty5.util.internal.ObjectUtil, net.jpountz.lz4.LZ4Compressor, .LZ4Exception, .LZ4Factory, java.nio.ByteBuffer, java.util.function.Supplier, java.util.zip.Checksum

Compresses a Buffer using 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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final int
private final BufferChecksum
checksum

Underlying checksum calculator in use.

private final int
compressionLevel

Compression level of current LZ4 encoder (depends on blockSize).

private final LZ4Compressor
compressor

Underlying compressor in use.

pack-priv static final int
private final int
maxEncodeSize

Maximum size for any buffer to write encoded (compressed) data into.

private Lz4Compressor.State

Constructor Summary

AccessConstructor and Description
private
Lz4Compressor(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum, int maxEncodeSize)

Method Summary

Modifier and TypeMethod and Description
private Buffer
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.
input
,
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 void
compressData(Buffer in, Buffer out)

Encodes the input buffer into blockSize chunks in the output buffer.

private static int
compressionLevel(int blockSize)

Calculates compression level on the basis of block size.

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<Lz4Compressor>
newFactory()

Creates the fastest LZ4 compressor factory with default block size (64 KB) and xxhash hashing for Java, based on Yann Collet's work available at Github.

public static Supplier<Lz4Compressor>

Returns:

the factory.
newFactory
(boolean
if true codec will use compressor which requires more memory and is slower but compresses more efficiently
highCompressor
)

Creates a new LZ4 compressor factory with high or fast compression, default block size (64 KB) and xxhash hashing for Java, based on Yann Collet's work available at Github.

public static Supplier<Lz4Compressor>

Returns:

the factory.
newFactory
(LZ4Factory
user customizable LZ4Factory instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses the sun.misc.Unsafe
factory
,
boolean
if true codec will use compressor which requires more memory and is slower but compresses more efficiently
highCompressor
,
int
the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M
blockSize
,
Checksum
the Checksum instance to use to check data for integrity
checksum
)

Creates a new customizable LZ4 compressor factory.

public static Supplier<Lz4Compressor>

Returns:

the factory.
newFactory
(LZ4Factory
user customizable LZ4Factory instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses the sun.misc.Unsafe
factory
,
boolean
if true codec will use compressor which requires more memory and is slower but compresses more efficiently
highCompressor
,
int
the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M
blockSize
,
Checksum
the Checksum instance to use to check data for integrity
checksum
,
int
the maximum size for an encode (compressed) buffer
maxEncodeSize
)

Creates a new customizable LZ4 compressor factory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockSizeback to summary
private final int blockSize
checksumback to summary
private final BufferChecksum checksum

Underlying checksum calculator in use.

compressionLevelback to summary
private final int compressionLevel

Compression level of current LZ4 encoder (depends on blockSize).

compressorback to summary
private final LZ4Compressor compressor

Underlying compressor in use.

DEFAULT_MAX_ENCODE_SIZEback to summary
pack-priv static final int DEFAULT_MAX_ENCODE_SIZE
maxEncodeSizeback to summary
private final int maxEncodeSize

Maximum size for any buffer to write encoded (compressed) data into.

stateback to summary
private Lz4Compressor.State state

Constructor Detail

Lz4Compressorback to summary
private Lz4Compressor(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum, int maxEncodeSize)

Method Detail

allocateBufferback to summary
private Buffer allocateBuffer(BufferAllocator allocator, Buffer msg)
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 input, 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
input: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 void compressData(Buffer in, Buffer out)

Encodes the input buffer into blockSize chunks in the output buffer.

compressionLevelback to summary
private static int compressionLevel(int blockSize)

Calculates compression level on the basis of block size.

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<Lz4Compressor> newFactory()

Creates the fastest LZ4 compressor factory with default block size (64 KB) and xxhash hashing for Java, based on Yann Collet's work available at Github.

newFactoryback to summary
public static Supplier<Lz4Compressor> newFactory(boolean highCompressor)

Creates a new LZ4 compressor factory with high or fast compression, default block size (64 KB) and xxhash hashing for Java, based on Yann Collet's work available at Github.

Parameters
highCompressor:boolean

if true codec will use compressor which requires more memory and is slower but compresses more efficiently

Returns:Supplier<Lz4Compressor>

the factory.

newFactoryback to summary
public static Supplier<Lz4Compressor> newFactory(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum)

Creates a new customizable LZ4 compressor factory.

Parameters
factory:LZ4Factory

user customizable LZ4Factory instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses the sun.misc.Unsafe

highCompressor:boolean

if true codec will use compressor which requires more memory and is slower but compresses more efficiently

blockSize:int

the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M

checksum:Checksum

the Checksum instance to use to check data for integrity

Returns:Supplier<Lz4Compressor>

the factory.

newFactoryback to summary
public static Supplier<Lz4Compressor> newFactory(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum, int maxEncodeSize)

Creates a new customizable LZ4 compressor factory.

Parameters
factory:LZ4Factory

user customizable LZ4Factory instance which may be JNI bindings to the original C implementation, a pure Java implementation or a Java implementation that uses the sun.misc.Unsafe

highCompressor:boolean

if true codec will use compressor which requires more memory and is slower but compresses more efficiently

blockSize:int

the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M

checksum:Checksum

the Checksum instance to use to check data for integrity

maxEncodeSize:int

the maximum size for an encode (compressed) buffer

Returns:Supplier<Lz4Compressor>

the factory.

io.netty5.handler.codec.compression back to summary

private final Enum Lz4Compressor.State

extends Enum<Lz4Compressor.State>
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

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

Constructor Detail

Stateback to summary
private State()

Method Detail

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