Class FastLz
- java.lang.Object
-
- io.netty.handler.codec.compression.FastLz
-
final class FastLz extends java.lang.Object
Core of FastLZ compression algorithm. This class provides methods for compression and decompression of buffers and saves constants which use byFastLzFrameEncoder
andFastLzFrameDecoder
. This is refactored code of jfastlz library written by William Kinney.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static byte
BLOCK_TYPE_COMPRESSED
(package private) static byte
BLOCK_TYPE_NON_COMPRESSED
(package private) static byte
BLOCK_WITH_CHECKSUM
(package private) static byte
BLOCK_WITHOUT_CHECKSUM
(package private) static int
CHECKSUM_OFFSET
private static int
HASH_LOG
private static int
HASH_MASK
private static int
HASH_SIZE
(package private) static int
LEVEL_1
Level 1 is the fastest compression and generally useful for short data.(package private) static int
LEVEL_2
Level 2 is slightly slower but it gives better compression ratio.(package private) static int
LEVEL_AUTO
In this casecompress(byte[], int, int, byte[], int, int)
will choose level automatically depending on the length of the input buffer.(package private) static int
MAGIC_NUMBER
(package private) static int
MAX_CHUNK_LENGTH
private static int
MAX_COPY
private static int
MAX_DISTANCE
private static int
MAX_FARDISTANCE
private static int
MAX_LEN
(package private) static int
MIN_LENGTH_TO_COMPRESSION
Do not callcompress(byte[], int, int, byte[], int, int)
for input buffers which length less than this value.private static int
MIN_RECOMENDED_LENGTH_FOR_LEVEL_2
(package private) static int
OPTIONS_OFFSET
-
Constructor Summary
Constructors Modifier Constructor Description private
FastLz()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static int
calculateOutputBufferLength(int inputLength)
The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes.(package private) static int
compress(byte[] input, int inOffset, int inLength, byte[] output, int outOffset, int proposedLevel)
Compress a block of data in the input buffer and returns the size of compressed block.(package private) static int
decompress(byte[] input, int inOffset, int inLength, byte[] output, int outOffset, int outLength)
Decompress a block of compressed data and returns the size of the decompressed block.private static int
hashFunction(byte[] p, int offset)
private static int
readU16(byte[] data, int offset)
-
-
-
Field Detail
-
MAX_DISTANCE
private static final int MAX_DISTANCE
- See Also:
- Constant Field Values
-
MAX_FARDISTANCE
private static final int MAX_FARDISTANCE
- See Also:
- Constant Field Values
-
HASH_LOG
private static final int HASH_LOG
- See Also:
- Constant Field Values
-
HASH_SIZE
private static final int HASH_SIZE
- See Also:
- Constant Field Values
-
HASH_MASK
private static final int HASH_MASK
- See Also:
- Constant Field Values
-
MAX_COPY
private static final int MAX_COPY
- See Also:
- Constant Field Values
-
MAX_LEN
private static final int MAX_LEN
- See Also:
- Constant Field Values
-
MIN_RECOMENDED_LENGTH_FOR_LEVEL_2
private static final int MIN_RECOMENDED_LENGTH_FOR_LEVEL_2
- See Also:
- Constant Field Values
-
MAGIC_NUMBER
static final int MAGIC_NUMBER
- See Also:
- Constant Field Values
-
BLOCK_TYPE_NON_COMPRESSED
static final byte BLOCK_TYPE_NON_COMPRESSED
- See Also:
- Constant Field Values
-
BLOCK_TYPE_COMPRESSED
static final byte BLOCK_TYPE_COMPRESSED
- See Also:
- Constant Field Values
-
BLOCK_WITHOUT_CHECKSUM
static final byte BLOCK_WITHOUT_CHECKSUM
- See Also:
- Constant Field Values
-
BLOCK_WITH_CHECKSUM
static final byte BLOCK_WITH_CHECKSUM
- See Also:
- Constant Field Values
-
OPTIONS_OFFSET
static final int OPTIONS_OFFSET
- See Also:
- Constant Field Values
-
CHECKSUM_OFFSET
static final int CHECKSUM_OFFSET
- See Also:
- Constant Field Values
-
MAX_CHUNK_LENGTH
static final int MAX_CHUNK_LENGTH
- See Also:
- Constant Field Values
-
MIN_LENGTH_TO_COMPRESSION
static final int MIN_LENGTH_TO_COMPRESSION
Do not callcompress(byte[], int, int, byte[], int, int)
for input buffers which length less than this value.- See Also:
- Constant Field Values
-
LEVEL_AUTO
static final int LEVEL_AUTO
In this casecompress(byte[], int, int, byte[], int, int)
will choose level automatically depending on the length of the input buffer. If length less thanMIN_RECOMENDED_LENGTH_FOR_LEVEL_2
LEVEL_1
will be chosen, otherwiseLEVEL_2
.- See Also:
- Constant Field Values
-
LEVEL_1
static final int LEVEL_1
Level 1 is the fastest compression and generally useful for short data.- See Also:
- Constant Field Values
-
LEVEL_2
static final int LEVEL_2
Level 2 is slightly slower but it gives better compression ratio.- See Also:
- Constant Field Values
-
-
Method Detail
-
calculateOutputBufferLength
static int calculateOutputBufferLength(int inputLength)
The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes.- Parameters:
inputLength
- length of input buffer- Returns:
- Maximum output buffer length
-
compress
static int compress(byte[] input, int inOffset, int inLength, byte[] output, int outOffset, int proposedLevel)
Compress a block of data in the input buffer and returns the size of compressed block. The size of input buffer is specified by length. The minimum input buffer size is 32. If the input is not compressible, the return value might be larger than length (input buffer size).
-
decompress
static int decompress(byte[] input, int inOffset, int inLength, byte[] output, int outOffset, int outLength)
Decompress a block of compressed data and returns the size of the decompressed block. If error occurs, e.g. the compressed data is corrupted or the output buffer is not large enough, then 0 (zero) will be returned instead. Decompression is memory safe and guaranteed not to write the output buffer more than what is specified in outLength.
-
hashFunction
private static int hashFunction(byte[] p, int offset)
-
readU16
private static int readU16(byte[] data, int offset)
-
-