public class UnsafeChunkDecoder extends ChunkDecoder
ChunkDecoder
implementation that uses
Sun JDK's Unsafe class (which may be included by other JDK's as well;
IBM's apparently does).
Credits for the idea go to Dain Sundstrom, who kindly suggested this use, and is all-around great source for optimization tips and tricks. Big thanks also to LZ4-java developers, whose stellar performance made me go back and see what more I can do to optimize this code!
Modifier and Type | Field and Description |
---|---|
private static long |
BYTE_ARRAY_OFFSET |
private static sun.misc.Unsafe |
unsafe |
BYTE_NULL, HEADER_BYTES
Constructor and Description |
---|
UnsafeChunkDecoder() |
Modifier and Type | Method and Description |
---|---|
private static void |
copyLong(byte[] buffer,
int inputIndex,
int outputIndex,
int length,
int outputEnd8) |
private static void |
copyLongTail(byte[] buffer,
int inputIndex,
int outputIndex,
int length) |
private static int |
copyOverlappingLong(byte[] out,
int outPos,
int offset,
int len) |
private int |
copyOverlappingShort(byte[] out,
int outPos,
int offset,
int len) |
private static void |
copyUpTo32(byte[] in,
int inputIndex,
byte[] out,
int outputIndex,
int lengthMinusOne) |
private static void |
copyUpTo32(byte[] buffer,
int inputIndex,
int outputIndex,
int lengthMinusOne) |
void |
decodeChunk(byte[] in,
int inPos,
byte[] out,
int outPos,
int outEnd)
Main decode method for individual chunks.
|
int |
decodeChunk(java.io.InputStream is,
byte[] inputBuffer,
byte[] outputBuffer)
Main decode from a stream.
|
int |
skipOrDecodeChunk(java.io.InputStream is,
byte[] inputBuffer,
byte[] outputBuffer,
long maxToSkip) |
_reportArrayOverflow, _reportCorruptHeader, calculateUncompressedSize, decode, decode, decode, decode, readFully, readHeader, skipFully, uint16
private static final sun.misc.Unsafe unsafe
private static final long BYTE_ARRAY_OFFSET
public final int decodeChunk(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer) throws java.io.IOException
ChunkDecoder
decodeChunk
in class ChunkDecoder
is
- An input stream of LZF compressed bytesinputBuffer
- A byte array used as a scratch area.outputBuffer
- A byte array in which the result is returnedjava.io.IOException
public final void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFException
ChunkDecoder
decodeChunk
in class ChunkDecoder
LZFException
public int skipOrDecodeChunk(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) throws java.io.IOException
skipOrDecodeChunk
in class ChunkDecoder
returnValue = -(decodedAmount + 2)
)java.io.IOException
private final int copyOverlappingShort(byte[] out, int outPos, int offset, int len)
private static final int copyOverlappingLong(byte[] out, int outPos, int offset, int len)
private static final void copyUpTo32(byte[] buffer, int inputIndex, int outputIndex, int lengthMinusOne)
private static final void copyUpTo32(byte[] in, int inputIndex, byte[] out, int outputIndex, int lengthMinusOne)
private static final void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8)
private static final void copyLongTail(byte[] buffer, int inputIndex, int outputIndex, int length)