Class UnsafeChunkDecoder
java.lang.Object
com.ning.compress.lzf.ChunkDecoder
com.ning.compress.lzf.impl.UnsafeChunkDecoder
Highly optimized
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!
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longprivate static final sun.misc.UnsafeFields inherited from class ChunkDecoder
BYTE_NULL, HEADER_BYTES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static final voidcopyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8) private static final voidcopyLongTail(byte[] buffer, int inputIndex, int outputIndex, int length) private static final intcopyOverlappingLong(byte[] out, int outPos, int offset, int len) private final intcopyOverlappingShort(byte[] out, int outPos, int offset, int len) private static final voidcopyUpTo32(byte[] in, int inputIndex, byte[] out, int outputIndex, int lengthMinusOne) private static final voidcopyUpTo32(byte[] buffer, int inputIndex, int outputIndex, int lengthMinusOne) final voiddecodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) Main decode method for individual chunks.final intdecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer) Main decode from a stream.intskipOrDecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) Methods inherited from class ChunkDecoder
_reportArrayOverflow, _reportCorruptHeader, calculateUncompressedSize, decode, decode, decode, decode, readFully, readHeader, skipFully, uint16
-
Field Details
-
unsafe
private static final sun.misc.Unsafe unsafe -
BYTE_ARRAY_OFFSET
private static final long BYTE_ARRAY_OFFSET
-
-
Constructor Details
-
UnsafeChunkDecoder
public UnsafeChunkDecoder()
-
-
Method Details
-
decodeChunk
public final int decodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer) throws IOException Description copied from class:ChunkDecoderMain decode from a stream. Decompressed bytes are placed in the outputBuffer, inputBuffer is a "scratch-area".- Specified by:
decodeChunkin classChunkDecoder- Parameters:
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 returned- Returns:
- The number of bytes placed in the outputBuffer.
- Throws:
IOException
-
decodeChunk
public final void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFException Description copied from class:ChunkDecoderMain decode method for individual chunks.- Specified by:
decodeChunkin classChunkDecoder- Throws:
LZFException
-
skipOrDecodeChunk
public int skipOrDecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) throws IOException - Specified by:
skipOrDecodeChunkin classChunkDecoder- Returns:
- If positive number, number of bytes skipped; if -1, end-of-stream was
reached; otherwise, amount of content
decoded (using formula of
returnValue = -(decodedAmount + 2)) - Throws:
IOException
-
copyOverlappingShort
private final int copyOverlappingShort(byte[] out, int outPos, int offset, int len) -
copyOverlappingLong
private static final int copyOverlappingLong(byte[] out, int outPos, int offset, int len) -
copyUpTo32
private static final void copyUpTo32(byte[] buffer, int inputIndex, int outputIndex, int lengthMinusOne) -
copyUpTo32
private static final void copyUpTo32(byte[] in, int inputIndex, byte[] out, int outputIndex, int lengthMinusOne) -
copyLong
private static final void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8) -
copyLongTail
private static final void copyLongTail(byte[] buffer, int inputIndex, int outputIndex, int length)
-