public final class CompressLZF
extends java.lang.Object
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 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 int |
HASH_SIZE
The number of entries in the hash table.
|
private static int |
MAX_LITERAL
The maximum number of literals in a chunk (32).
|
private static int |
MAX_OFF
The maximum offset allowed for a back-reference (8192).
|
private static int |
MAX_REF
The maximum back-reference length (264).
|
| Constructor and Description |
|---|
CompressLZF() |
| Modifier and Type | Method and Description |
|---|---|
int |
compress(byte[] in,
int inLen,
byte[] out,
int outPos) |
void |
expand(java.nio.ByteBuffer in,
int inPos,
byte[] out,
int outPos,
int outLen) |
void |
expand(java.io.DataInput in,
byte[] out,
int outPos,
int outLen) |
private static int |
first(byte[] in,
int inPos)
Return byte with lower 2 bytes being byte at index, then index+1.
|
private static int |
hash(int h)
Compute the address in the hash table.
|
private static int |
next(int v,
byte[] in,
int inPos)
Shift v 1 byte left, add value at index inPos+2.
|
private static final int HASH_SIZE
private static final int MAX_LITERAL
private static final int MAX_OFF
private static final int MAX_REF
private int[] cachedHashTable
private static int first(byte[] in,
int inPos)
private static int next(int v,
byte[] in,
int inPos)
private static int hash(int h)
public int compress(byte[] in,
int inLen,
byte[] out,
int outPos)
public void expand(java.io.DataInput in,
byte[] out,
int outPos,
int outLen)
throws java.io.IOException
java.io.IOExceptionpublic void expand(java.nio.ByteBuffer in,
int inPos,
byte[] out,
int outPos,
int outLen)