public abstract class ChunkEncoder extends Object implements Closeable
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 int |
_hashModulo |
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 BufferRecycler |
_recycler |
protected static int |
MAX_HASH_SIZE |
protected static int |
MAX_OFF |
protected static int |
MAX_REF |
protected static int |
MIN_BLOCK_TO_COMPRESS |
protected static int |
MIN_HASH_SIZE |
protected static 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?
|
Modifier | Constructor and Description |
---|---|
protected |
ChunkEncoder(int totalLength) |
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.
|
Modifier and Type | Method and Description |
---|---|
int |
appendEncodedChunk(byte[] input,
int inputPtr,
int inputLen,
byte[] outputBuffer,
int outputPos)
Alternate chunk compression method that will append encoded chunk in
pre-allocated buffer.
|
void |
close()
Method to close once encoder is no longer in use.
|
void |
encodeAndWriteChunk(byte[] data,
int offset,
int len,
OutputStream out)
Method for encoding individual chunk, writing it to given output stream.
|
LZFChunk |
encodeChunk(byte[] data,
int offset,
int len)
Method for compressing (or not) individual chunks
|
protected int |
hash(int h) |
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)
|
protected static final int MIN_BLOCK_TO_COMPRESS
protected static final int MIN_HASH_SIZE
protected static final int MAX_HASH_SIZE
protected static final int MAX_OFF
protected static final int MAX_REF
protected static final int TAIL_LENGTH
protected final BufferRecycler _recycler
protected int[] _hashTable
protected final int _hashModulo
protected byte[] _encodeBuffer
protected byte[] _headerBuffer
protected ChunkEncoder(int totalLength)
totalLength
- Total encoded length; used for calculating size
of hash table to useprotected ChunkEncoder(int totalLength, boolean bogus)
public final void close()
encodeChunk(byte[], int, int)
will failclose
in interface Closeable
close
in interface AutoCloseable
public LZFChunk encodeChunk(byte[] data, int offset, int len)
public int appendEncodedChunk(byte[] input, int inputPtr, int inputLen, byte[] outputBuffer, int outputPos)
LZFEncoder.estimateMaxWorkspaceSize(int)
to calculate
necessary buffer size.public void encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out) throws IOException
IOException
protected abstract int tryCompress(byte[] in, int inPos, int inEnd, byte[] out, int outPos)
result - originalOutPost
is the actual length of compressed chunk (without header)protected final int hash(int h)
Copyright © 2014. All rights reserved.