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

public final Class Bzip2Compressor

extends Object
implements Compressor
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.compression.Compressor, java.lang.AutoCloseable
Imports
io.netty5.buffer.Buffer, .BufferAllocator, java.util.function.Supplier

Compresses a Buffer using the Bzip2 algorithm. See Bzip2.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private static enum
Bzip2Compressor.State

Current state of stream.

Field Summary

Modifier and TypeField and Description
private Bzip2BlockCompressor
blockCompressor

The compressor for the current block.

private Bzip2Compressor.CompressorState
private Bzip2Compressor.State
private final int
streamBlockSize

The declared maximum block size of the stream (before final run-length decoding).

private int
streamCRC

The merged CRC of all blocks compressed so far.

private final Bzip2BitWriter
writer

A writer that provides bit-level writes.

Constructor Summary

AccessConstructor and Description
private
Bzip2Compressor(final int
The Bzip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9). Larger block sizes require more memory for both compression and decompression, but give better compression ratios. 9 will usually be the best value to use.
blockSizeMultiplier
)

Creates a new bzip2 compressor with the specified blockSizeMultiplier.

Method Summary

Modifier and TypeMethod and Description
public void
close()

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

# Close the compressor.
private void
closeBlock(Buffer out)

Close current block and update streamCRC.

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 Buffer
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<Bzip2Compressor>

Returns:

the factory.
newFactory
()

Creates a new bzip2 compressor factory with the maximum (900,000 byte) block size.

public static Supplier<Bzip2Compressor>

Returns:

the factory.
newFactory
(final int
The Bzip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9). Larger block sizes require more memory for both compression and decompression, but give better compression ratios. 9 will usually be the best value to use.
blockSizeMultiplier
)

Creates a new bzip2 compressor factory with the specified blockSizeMultiplier.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockCompressorback to summary
private Bzip2BlockCompressor blockCompressor

The compressor for the current block.

compressorStateback to summary
private Bzip2Compressor.CompressorState compressorState
currentStateback to summary
private Bzip2Compressor.State currentState
streamBlockSizeback to summary
private final int streamBlockSize

The declared maximum block size of the stream (before final run-length decoding).

streamCRCback to summary
private int streamCRC

The merged CRC of all blocks compressed so far.

writerback to summary
private final Bzip2BitWriter writer

A writer that provides bit-level writes.

Constructor Detail

Bzip2Compressorback to summary
private Bzip2Compressor(final int blockSizeMultiplier)

Creates a new bzip2 compressor with the specified blockSizeMultiplier.

Parameters
blockSizeMultiplier:int

The Bzip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9). Larger block sizes require more memory for both compression and decompression, but give better compression ratios. 9 will usually be the best value to use.

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
closeBlockback to summary
private void closeBlock(Buffer out)

Close current block and update streamCRC.

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.
compressDataback to summary
private Buffer compressData(Buffer in, BufferAllocator allocator)
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<Bzip2Compressor> newFactory()

Creates a new bzip2 compressor factory with the maximum (900,000 byte) block size.

Returns:Supplier<Bzip2Compressor>

the factory.

newFactoryback to summary
public static Supplier<Bzip2Compressor> newFactory(final int blockSizeMultiplier)

Creates a new bzip2 compressor factory with the specified blockSizeMultiplier.

Parameters
blockSizeMultiplier:int

The Bzip2 block size as a multiple of 100,000 bytes (minimum 1, maximum 9). Larger block sizes require more memory for both compression and decompression, but give better compression ratios. 9 will usually be the best value to use.

Returns:Supplier<Bzip2Compressor>

the factory.

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

private final Enum Bzip2Compressor.CompressorState

extends Enum<Bzip2Compressor.CompressorState>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Bzip2Compressor.CompressorState
public static final Bzip2Compressor.CompressorState
public static final Bzip2Compressor.CompressorState

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CLOSEDback to summary
public static final Bzip2Compressor.CompressorState CLOSED
FINISHEDback to summary
public static final Bzip2Compressor.CompressorState FINISHED
PROCESSINGback to summary
public static final Bzip2Compressor.CompressorState PROCESSING

Constructor Detail

CompressorStateback to summary
private CompressorState()

Method Detail

valueOfback to summary
public static Bzip2Compressor.CompressorState valueOf(String name)
valuesback to summary
public static Bzip2Compressor.CompressorState[] values()
io.netty5.handler.codec.compression back to summary

private final Enum Bzip2Compressor.State

extends Enum<Bzip2Compressor.State>
Class Inheritance

Current state of stream.

Field Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CLOSE_BLOCKback to summary
public static final Bzip2Compressor.State CLOSE_BLOCK
INITback to summary
public static final Bzip2Compressor.State INIT
INIT_BLOCKback to summary
public static final Bzip2Compressor.State INIT_BLOCK
WRITE_DATAback to summary
public static final Bzip2Compressor.State WRITE_DATA

Constructor Detail

Stateback to summary
private State()

Method Detail

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