Top Description Fields Constructors Methods
com.ning.compress.lzf.impl

public Class UnsafeChunkDecoder

extends ChunkDecoder
Class Inheritance
Annotations
@SuppressWarnings:restriction
Imports
java.io.IOException, .InputStream, java.lang.reflect.Field, sun.misc.Unsafe, com.ning.compress.lzf.*

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

Modifier and TypeField and Description
private static final long
private static final Unsafe
Inherited from com.ning.compress.lzf.ChunkDecoder:
BYTE_NULLHEADER_BYTES

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
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)

private static final int
copyOverlappingLong(final byte[] out, int outPos, final int offset, int len)

private final int
copyOverlappingShort(final byte[] out, int outPos, final 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)

public final int
decodeChunk(final InputStream
An input stream of LZF compressed bytes
is
,
final byte[]
A byte array used as a scratch area.
inputBuffer
,
final byte[]
A byte array in which the result is returned
outputBuffer
)

Implements abstract com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Main decode from a stream.
public final void
decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd)

Implements abstract com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Main decode method for individual chunks.
public int
skipOrDecodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer, final long maxToSkip)

Implements abstract com.ning.compress.lzf.ChunkDecoder.skipOrDecodeChunk.

Inherited from com.ning.compress.lzf.ChunkDecoder:
_reportArrayOverflow_reportCorruptHeadercalculateUncompressedSizedecodedecodedecodedecodereadFullyreadHeaderskipFullyuint16

Field Detail

BYTE_ARRAY_OFFSETback to summary
private static final long BYTE_ARRAY_OFFSET
unsafeback to summary
private static final Unsafe unsafe

Constructor Detail

UnsafeChunkDecoderback to summary
public UnsafeChunkDecoder()

Method Detail

copyLongback to summary
private static final void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8)
copyLongTailback to summary
private static final void copyLongTail(byte[] buffer, int inputIndex, int outputIndex, int length)
copyOverlappingLongback to summary
private static final int copyOverlappingLong(final byte[] out, int outPos, final int offset, int len)
copyOverlappingShortback to summary
private final int copyOverlappingShort(final byte[] out, int outPos, final int offset, int len)
copyUpTo32back to summary
private static final void copyUpTo32(byte[] buffer, int inputIndex, int outputIndex, int lengthMinusOne)
copyUpTo32back to summary
private static final void copyUpTo32(byte[] in, int inputIndex, byte[] out, int outputIndex, int lengthMinusOne)
decodeChunkback to summary
public final int decodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer) throws IOException

Implements abstract com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Doc from com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Main decode from a stream. Decompressed bytes are placed in the outputBuffer, inputBuffer is a "scratch-area".

Parameters
is:InputStream

An input stream of LZF compressed bytes

inputBuffer:byte[]

A byte array used as a scratch area.

outputBuffer:byte[]

A byte array in which the result is returned

Returns:int

The number of bytes placed in the outputBuffer.

Annotations
@Override
decodeChunkback to summary
public final void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFException

Implements abstract com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Doc from com.ning.compress.lzf.ChunkDecoder.decodeChunk.

Main decode method for individual chunks.

Annotations
@Override
skipOrDecodeChunkback to summary
public int skipOrDecodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer, final long maxToSkip) throws IOException

Implements abstract com.ning.compress.lzf.ChunkDecoder.skipOrDecodeChunk.

Returns:int

Doc from com.ning.compress.lzf.ChunkDecoder.skipOrDecodeChunk.

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))

Annotations
@Override