This class implements the LZF lossless data compression algorithm. LZF is a Lempel-Ziv variant with byte-aligned output, and optimized for speed.
Safety/Use Notes:
The LZF compressed format knows literal runs and back-references:
The first byte of the compressed stream is the control byte. For literal runs, the highest three bits of the control byte are not set, the lower bits are the literal run length, and the next bytes are data to copy directly into the output. For back-references, the highest three bits of the control byte are the back-reference length. If all three bits are set, then the back-reference length is stored in the next byte. The lower bits of the control byte combined with the next byte form the offset for the back-reference.
| Modifier and Type | Field and Description |
|---|---|
| private int[] | cachedHashTable
Hash table for matching byte sequences (reused for performance). |
| private static final int | HASH_SIZE
The number of entries in the hash table. |
| private static final int | MAX_LITERAL
The maximum number of literals in a chunk (32). |
| private static final int | MAX_OFF
The maximum offset allowed for a back-reference (8192). |
| private static final int | MAX_REF
The maximum back-reference length (264). |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | compress(byte[]
the input data in, int the offset at the input array inPos, int the number of bytes to compress inLen, byte[] the output area out, int the offset at the output array outPos)Implements org. Compress a number of bytes. |
| public int | Returns: the end positionthe input data in, int the offset at the input buffer inPos, byte[] the output area out, int the offset at the output array outPos)Compress a number of bytes. |
| public void | expand(byte[]
the compressed data in, int the offset at the input array inPos, int the number of bytes to read inLen, byte[] the output area out, int the offset at the output array outPos, int the size of the uncompressed data outLen)Implements org. Expand a number of compressed bytes. |
| public static void | expand(ByteBuffer
the compressed data in, ByteBuffer the output area out)Expand a number of compressed bytes. |
| private static int | first(byte[] in, int inPos)
Return the integer with the first two bytes 0, then the bytes at the index, then at index+1. |
| private static int | first(ByteBuffer in, int inPos)
Return the integer with the first two bytes 0, then the bytes at the index, then at index+1. |
| public int | getAlgorithm()
Implements org. Get the compression algorithm type. |
| private static int | |
| private static int | |
| private static int | next(int v, ByteBuffer in, int inPos)
Shift the value 1 byte left, and add the byte at index inPos+2. |
| public void | setOptions(String
the options options)Implements org. Set the compression options. |
| cachedHashTable | back to summary |
|---|---|
| private int[] cachedHashTable Hash table for matching byte sequences (reused for performance). | |
| HASH_SIZE | back to summary |
|---|---|
| private static final int HASH_SIZE The number of entries in the hash table. The size is a trade-off between hash collisions (reduced compression) and speed (amount that fits in CPU cache). | |
| MAX_LITERAL | back to summary |
|---|---|
| private static final int MAX_LITERAL The maximum number of literals in a chunk (32). | |
| MAX_OFF | back to summary |
|---|---|
| private static final int MAX_OFF The maximum offset allowed for a back-reference (8192). | |
| MAX_REF | back to summary |
|---|---|
| private static final int MAX_REF The maximum back-reference length (264). | |
| CompressLZF | back to summary |
|---|---|
| public CompressLZF() | |
| compress | back to summary |
|---|---|
| public int compress(byte[] in, int inPos, int inLen, byte[] out, int outPos) Implements org. Doc from org. Compress a number of bytes.
| |
| compress | back to summary |
|---|---|
| public int compress(ByteBuffer in, int inPos, byte[] out, int outPos) Compress a number of bytes.
| |
| expand | back to summary |
|---|---|
| public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) Implements org. Doc from org. Expand a number of compressed bytes.
| |
| expand | back to summary |
|---|---|
| public static void expand(ByteBuffer in, ByteBuffer out) Expand a number of compressed bytes.
| |
| first | back to summary |
|---|---|
| private static int first(byte[] in, int inPos) Return the integer with the first two bytes 0, then the bytes at the index, then at index+1. | |
| first | back to summary |
|---|---|
| private static int first(ByteBuffer in, int inPos) Return the integer with the first two bytes 0, then the bytes at the index, then at index+1. | |
| getAlgorithm | back to summary |
|---|---|
| public int getAlgorithm() Implements org. Doc from org. Get the compression algorithm type.
| |
| hash | back to summary |
|---|---|
| private static int hash(int h) Compute the address in the hash table. | |
| next | back to summary |
|---|---|
| private static int next(int v, byte[] in, int inPos) Shift the value 1 byte left, and add the byte at index inPos+2. | |
| next | back to summary |
|---|---|
| private static int next(int v, ByteBuffer in, int inPos) Shift the value 1 byte left, and add the byte at index inPos+2. | |
| setOptions | back to summary |
|---|---|
| public void setOptions(String options) Implements org. Doc from org. Set the compression options. This may include settings for higher performance but less compression. | |