Note that instances are stateful and hence not thread-safe; one instance is meant to be used for processing a sequence of chunks where total length is known.
| Modifier and Type | Field and Description |
|---|---|
| protected byte[] | _encodeBuffer
Buffer in which encoded content is stored during processing |
| protected final int | |
| protected int[] | _hashTable
Hash table contains lookup based on 3-byte sequence; key is hash of such triplet, value is offset in buffer. |
| protected byte[] | _headerBuffer
Small buffer passed to LZFChunk, needed for writing chunk header |
| protected final BufferRecycler | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| protected static final int | |
| protected static final int | TAIL_LENGTH
How many tail bytes are we willing to just copy as is, to simplify loop end checks? |
| Access | Constructor and Description |
|---|---|
| protected | ChunkEncoder(int
Total encoded length; used for calculating size
of hash table to use totalLength)Uses a ThreadLocal soft-referenced BufferRecycler instance. |
| protected | ChunkEncoder(int
Total encoded length; used for calculating size
of hash table to use totalLength, BufferRecycler Buffer recycler instance, for usages where the
caller manages the recycler instances bufferRecycler)
|
| protected | ChunkEncoder(int totalLength, boolean bogus)
Alternate constructor used when we want to avoid allocation encoding buffer, in cases where caller wants full control over allocations. |
| protected | ChunkEncoder(int totalLength, BufferRecycler bufferRecycler, boolean bogus)
Alternate constructor used when we want to avoid allocation encoding buffer, in cases where caller wants full control over allocations. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: Offset in output buffer after appending the encoded chunkAlternate chunk compression method that will append encoded chunk in pre-allocated buffer. |
| public int | Returns: Offset after appending compressed chunk, if compression produces compact enough chunk; otherwise -1 to indicate that no compression resulted.Value between 0.05 and 1.10 to indicate maximum relative size of
the result to use, in order to append encoded chunk maxResultRatio, final int inputPtr, final int inputLen, final byte[] outputBuffer, final int outputPos)Method similar to |
| private static int | |
| public final void | |
| public void | encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out)
Method for encoding individual chunk, writing it to given output stream. |
| public boolean | Returns: True if compression occurred and chunk was written; false if not.Method for encoding individual chunk, writing it to given output stream, if (and only if!) it compresses enough. |
| public LZFChunk | |
| public LZFChunk | Returns: Encoded chunk if (and only if) input compresses down to specified ratio or less; otherwise returns nullValue between 0.05 and 1.10 to indicate maximum relative size of
the result to use, in order to append encoded chunk maxResultRatio)Method for compressing individual chunk, if (and only if) it compresses down to specified ratio or less. |
| public BufferRecycler | |
| protected final int | |
| protected abstract int | Returns: Output pointer after handling content, such thatresult - originalOutPost
is the actual length of compressed chunk (without header)Main workhorse method that will try to compress given chunk, and return end position (offset to byte after last included byte). |
| _encodeBuffer | back to summary |
|---|---|
| protected byte[] _encodeBuffer Buffer in which encoded content is stored during processing | |
| _hashModulo | back to summary |
|---|---|
| protected final int _hashModulo | |
| _hashTable | back to summary |
|---|---|
| protected int[] _hashTable Hash table contains lookup based on 3-byte sequence; key is hash of such triplet, value is offset in buffer. | |
| _headerBuffer | back to summary |
|---|---|
| protected byte[] _headerBuffer Small buffer passed to LZFChunk, needed for writing chunk header | |
| _recycler | back to summary |
|---|---|
| protected final BufferRecycler _recycler | |
| MAX_HASH_SIZE | back to summary |
|---|---|
| protected static final int MAX_HASH_SIZE | |
| MAX_OFF | back to summary |
|---|---|
| protected static final int MAX_OFF | |
| MAX_REF | back to summary |
|---|---|
| protected static final int MAX_REF | |
| MIN_BLOCK_TO_COMPRESS | back to summary |
|---|---|
| protected static final int MIN_BLOCK_TO_COMPRESS | |
| MIN_HASH_SIZE | back to summary |
|---|---|
| protected static final int MIN_HASH_SIZE | |
| TAIL_LENGTH | back to summary |
|---|---|
| protected static final int TAIL_LENGTH How many tail bytes are we willing to just copy as is, to simplify loop end checks? 4 is bare minimum, may be raised to 8? | |
| ChunkEncoder | back to summary |
|---|---|
| protected ChunkEncoder(int totalLength) Uses a ThreadLocal soft-referenced BufferRecycler instance.
| |
| ChunkEncoder | back to summary |
|---|---|
protected ChunkEncoder(int totalLength, BufferRecycler bufferRecycler)
| |
| ChunkEncoder | back to summary |
|---|---|
| protected ChunkEncoder(int totalLength, boolean bogus) Alternate constructor used when we want to avoid allocation encoding buffer, in cases where caller wants full control over allocations. | |
| ChunkEncoder | back to summary |
|---|---|
| protected ChunkEncoder(int totalLength, BufferRecycler bufferRecycler, boolean bogus) Alternate constructor used when we want to avoid allocation encoding buffer, in cases where caller wants full control over allocations. | |
| appendEncodedChunk | back to summary |
|---|---|
| public int appendEncodedChunk(final byte[] input, final int inputPtr, final int inputLen, final byte[] outputBuffer, final int outputPos) Alternate chunk compression method that will append encoded chunk in
pre-allocated buffer. Note that caller must ensure that the buffer is
large enough to hold not just encoded result but also intermediate
result; latter may be up to 4% larger than input; caller may use
| |
| appendEncodedIfCompresses | back to summary |
|---|---|
| public int appendEncodedIfCompresses(final byte[] input, double maxResultRatio, final int inputPtr, final int inputLen, final byte[] outputBuffer, final int outputPos) Method similar to
| |
| calcHashLen | back to summary |
|---|---|
| private static int calcHashLen(int chunkSize) | |
| close | back to summary |
|---|---|
| public final void close() Implements java. Method to close once encoder is no longer in use. Note after calling
this method, further calls to
| |
| encodeAndWriteChunk | back to summary |
|---|---|
| public void encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out) throws IOException Method for encoding individual chunk, writing it to given output stream. | |
| encodeAndWriteChunkIfCompresses | back to summary |
|---|---|
| public boolean encodeAndWriteChunkIfCompresses(byte[] data, int offset, int inputLen, OutputStream out, double resultRatio) throws IOException Method for encoding individual chunk, writing it to given output stream, if (and only if!) it compresses enough.
| |
| encodeChunk | back to summary |
|---|---|
| public LZFChunk encodeChunk(byte[] data, int offset, int len) Method for compressing (or not) individual chunks | |
| encodeChunkIfCompresses | back to summary |
|---|---|
| public LZFChunk encodeChunkIfCompresses(byte[] data, int offset, int inputLen, double maxResultRatio) Method for compressing individual chunk, if (and only if) it compresses down to specified ratio or less.
| |
| getBufferRecycler | back to summary |
|---|---|
| public BufferRecycler getBufferRecycler() | |
| hash | back to summary |
|---|---|
| protected final int hash(int h) | |
| tryCompress | back to summary |
|---|---|
| protected abstract int tryCompress(byte[] in, int inPos, int inEnd, byte[] out, int outPos) Main workhorse method that will try to compress given chunk, and return end position (offset to byte after last included byte). Result will be "raw" encoded contents without chunk header information: caller is responsible for prepending header, if it chooses to use encoded data; it may also choose to instead create an uncompressed chunk.
| |