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

public final Class LzfCompressor

extends Object
implements Compressor
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.compression.Compressor, java.lang.AutoCloseable
Imports
com.ning.compress.BufferRecycler, com.ning.compress.lzf.ChunkEncoder, .LZFChunk, .LZFEncoder, com.ning.compress.lzf.util.ChunkEncoderFactory, io.netty5.buffer.Buffer, .BufferAllocator, java.util.function.Supplier

Compresses a Buffer using the LZF format.

See original LZF package and LZF format for full description.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final int
compressThreshold

Compress threshold for LZF format.

private final ChunkEncoder
encoder

Underlying decoder in use.

private static final int
MIN_BLOCK_TO_COMPRESS

Minimum block size ready for compression.

private final BufferRecycler
recycler

Object that handles details of buffer recycling.

private LzfCompressor.State

Constructor Summary

AccessConstructor and Description
private
LzfCompressor(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
,
int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
,
int
Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.
compressThreshold
)

Creates a new LZF compressor with specified settings.

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.
in
,
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 int
encodeCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

private static int
encodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

Use lzf uncompressed format to encode a piece of input.

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.
private static int
lzfEncodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

public static Supplier<LzfCompressor>

Returns:

the factory.
newFactory
()

Creates a new LZF compressor factory with the most optimal available methods for underlying data access.

public static Supplier<LzfCompressor>

Returns:

the factory.
newFactory
(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
)

Creates a new LZF compressor factory with specified encoding instance.

public static Supplier<LzfCompressor>

Returns:

the factory.
newFactory
(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
,
int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
)

Creates a new LZF compressor factory with specified encoding instance and compressThreshold.

public static Supplier<LzfCompressor>

Returns:

the factory.
newFactory
(int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
)

Creates a new LZF compressor factory with specified total length of encoded chunk.

public static Supplier<LzfCompressor>

Returns:

the factory.
newFactory
(boolean
If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).
safeInstance
,
int
Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.
totalLength
,
int
Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.
compressThreshold
)

Creates a new LZF compressor factory with specified settings.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

compressThresholdback to summary
private final int compressThreshold

Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.

When the value is less than ChunkEncoder#MIN_BLOCK_TO_COMPRESS, since LZF will not compress data that is less than ChunkEncoder#MIN_BLOCK_TO_COMPRESS, compressThreshold will not work.

See Also
ChunkEncoder#MIN_BLOCK_TO_COMPRESS
encoderback to summary
private final ChunkEncoder encoder

Underlying decoder in use.

MIN_BLOCK_TO_COMPRESSback to summary
private static final int MIN_BLOCK_TO_COMPRESS

Minimum block size ready for compression. Blocks with length less than MIN_BLOCK_TO_COMPRESS will write as uncompressed.

recyclerback to summary
private final BufferRecycler recycler

Object that handles details of buffer recycling.

stateback to summary
private LzfCompressor.State state

Constructor Detail

LzfCompressorback to summary
private LzfCompressor(boolean safeInstance, int totalLength, int compressThreshold)

Creates a new LZF compressor with specified settings.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

compressThreshold:int

Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.

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 in, 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
in: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.
encodeCompressback to summary
private int encodeCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)
encodeNonCompressback to summary
private static int encodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)

Use lzf uncompressed format to encode a piece of input.

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
lzfEncodeNonCompressback to summary
private static int lzfEncodeNonCompress(byte[] input, int inputPtr, int length, byte[] output, int outputPtr)
newFactoryback to summary
public static Supplier<LzfCompressor> newFactory()

Creates a new LZF compressor 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 use newFactory(boolean) with true param.

Returns:Supplier<LzfCompressor>

the factory.

newFactoryback to summary
public static Supplier<LzfCompressor> newFactory(boolean safeInstance)

Creates a new LZF compressor factory with specified encoding instance.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

Returns:Supplier<LzfCompressor>

the factory.

newFactoryback to summary
public static Supplier<LzfCompressor> newFactory(boolean safeInstance, int totalLength)

Creates a new LZF compressor factory with specified encoding instance and compressThreshold.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

Returns:Supplier<LzfCompressor>

the factory.

newFactoryback to summary
public static Supplier<LzfCompressor> newFactory(int totalLength)

Creates a new LZF compressor factory with specified total length of encoded chunk. You can configure it to encode your data flow more efficient if you know the average size of messages that you send.

Parameters
totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

Returns:Supplier<LzfCompressor>

the factory.

newFactoryback to summary
public static Supplier<LzfCompressor> newFactory(boolean safeInstance, int totalLength, int compressThreshold)

Creates a new LZF compressor factory with specified settings.

Parameters
safeInstance:boolean

If true encoder will use ChunkEncoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs. Otherwise encoder will try to use highly optimized ChunkEncoder implementation that uses Sun JDK's sun.misc.Unsafe class (which may be included by other JDK's as well).

totalLength:int

Expected total length of content to compress; only matters for outgoing messages that is smaller than maximum chunk size (64k), to optimize encoding hash tables.

compressThreshold:int

Compress threshold for LZF format. When the amount of input data is less than compressThreshold, we will construct an uncompressed output according to the LZF format.

Returns:Supplier<LzfCompressor>

the factory.

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

private final Enum LzfCompressor.State

extends Enum<LzfCompressor.State>
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

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

Constructor Detail

Stateback to summary
private State()

Method Detail

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