Class FramedLZ4CompressorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.compress.compressors.CompressorInputStream
-
- org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,InputStreamStatistics
public class FramedLZ4CompressorInputStream extends CompressorInputStream implements InputStreamStatistics
CompressorInputStream for the LZ4 frame format.Based on the "spec" in the version "1.5.1 (31/03/2015)"
- Since:
- 1.14
- See Also:
- LZ4 Frame Format Description
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intBLOCK_CHECKSUM_MASK(package private) static intBLOCK_INDEPENDENCE_MASK(package private) static intBLOCK_MAX_SIZE_MASKprivate byte[]blockDependencyBufferprivate XXHash32blockHash(package private) static intCONTENT_CHECKSUM_MASK(package private) static intCONTENT_SIZE_MASKprivate XXHash32contentHashprivate java.io.InputStreamcurrentBlockprivate booleandecompressConcatenatedprivate booleanendReachedprivate booleanexpectBlockChecksumprivate booleanexpectBlockDependencyprivate booleanexpectContentChecksumprivate booleanexpectContentSizeprivate CountingInputStreaminputStreamprivate booleaninUncompressed(package private) static byte[]LZ4_SIGNATUREprivate byte[]oneByteprivate static byteSKIPPABLE_FRAME_PREFIX_BYTE_MASKprivate static byte[]SKIPPABLE_FRAME_TRAILERprivate ByteUtils.ByteSuppliersupplier(package private) static intSUPPORTED_VERSION(package private) static intUNCOMPRESSED_FLAG_MASK(package private) static intVERSION_MASK
-
Constructor Summary
Constructors Constructor Description FramedLZ4CompressorInputStream(java.io.InputStream in)Creates a new input stream that decompresses streams compressed using the LZ4 frame format and stops after decompressing the first frame.FramedLZ4CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated)Creates a new input stream that decompresses streams compressed using the LZ4 frame format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidappendToBlockDependencyBuffer(byte[] b, int off, int len)voidclose()longgetCompressedCount()private voidinit(boolean firstFrame)private static booleanisSkippableFrameSignature(byte[] b)static booleanmatches(byte[] signature, int length)Checks if the signature matches what is expected for a .lz4 file.private voidmaybeFinishCurrentBlock()private voidnextBlock()intread()intread(byte[] b, int off, int len)private voidreadFrameDescriptor()private intreadOnce(byte[] b, int off, int len)private intreadOneByte()private booleanreadSignature(boolean firstFrame)private intskipSkippableFrame(byte[] b)Skips over the contents of a skippable frame as well as skippable frames following it.private voidverifyChecksum(XXHash32 hash, java.lang.String kind)private voidverifyContentChecksum()-
Methods inherited from class org.apache.commons.compress.compressors.CompressorInputStream
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytes
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.compress.utils.InputStreamStatistics
getUncompressedCount
-
-
-
-
Field Detail
-
LZ4_SIGNATURE
static final byte[] LZ4_SIGNATURE
-
SKIPPABLE_FRAME_TRAILER
private static final byte[] SKIPPABLE_FRAME_TRAILER
-
SKIPPABLE_FRAME_PREFIX_BYTE_MASK
private static final byte SKIPPABLE_FRAME_PREFIX_BYTE_MASK
- See Also:
- Constant Field Values
-
VERSION_MASK
static final int VERSION_MASK
- See Also:
- Constant Field Values
-
SUPPORTED_VERSION
static final int SUPPORTED_VERSION
- See Also:
- Constant Field Values
-
BLOCK_INDEPENDENCE_MASK
static final int BLOCK_INDEPENDENCE_MASK
- See Also:
- Constant Field Values
-
BLOCK_CHECKSUM_MASK
static final int BLOCK_CHECKSUM_MASK
- See Also:
- Constant Field Values
-
CONTENT_SIZE_MASK
static final int CONTENT_SIZE_MASK
- See Also:
- Constant Field Values
-
CONTENT_CHECKSUM_MASK
static final int CONTENT_CHECKSUM_MASK
- See Also:
- Constant Field Values
-
BLOCK_MAX_SIZE_MASK
static final int BLOCK_MAX_SIZE_MASK
- See Also:
- Constant Field Values
-
UNCOMPRESSED_FLAG_MASK
static final int UNCOMPRESSED_FLAG_MASK
- See Also:
- Constant Field Values
-
oneByte
private final byte[] oneByte
-
supplier
private final ByteUtils.ByteSupplier supplier
-
inputStream
private final CountingInputStream inputStream
-
decompressConcatenated
private final boolean decompressConcatenated
-
expectBlockChecksum
private boolean expectBlockChecksum
-
expectBlockDependency
private boolean expectBlockDependency
-
expectContentSize
private boolean expectContentSize
-
expectContentChecksum
private boolean expectContentChecksum
-
currentBlock
private java.io.InputStream currentBlock
-
endReached
private boolean endReached
-
inUncompressed
private boolean inUncompressed
-
contentHash
private final XXHash32 contentHash
-
blockHash
private final XXHash32 blockHash
-
blockDependencyBuffer
private byte[] blockDependencyBuffer
-
-
Constructor Detail
-
FramedLZ4CompressorInputStream
public FramedLZ4CompressorInputStream(java.io.InputStream in) throws java.io.IOExceptionCreates a new input stream that decompresses streams compressed using the LZ4 frame format and stops after decompressing the first frame.- Parameters:
in- the InputStream from which to read the compressed data- Throws:
java.io.IOException- if reading fails
-
FramedLZ4CompressorInputStream
public FramedLZ4CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated) throws java.io.IOExceptionCreates a new input stream that decompresses streams compressed using the LZ4 frame format.- Parameters:
in- the InputStream from which to read the compressed datadecompressConcatenated- if true, decompress until the end of the input; if false, stop after the first LZ4 frame and leave the input position to point to the next byte after the frame stream- Throws:
java.io.IOException- if reading fails
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
getCompressedCount
public long getCompressedCount()
- Specified by:
getCompressedCountin interfaceInputStreamStatistics- Returns:
- the amount of raw or compressed bytes read by the stream
- Since:
- 1.17
-
init
private void init(boolean firstFrame) throws java.io.IOException- Throws:
java.io.IOException
-
readSignature
private boolean readSignature(boolean firstFrame) throws java.io.IOException- Throws:
java.io.IOException
-
readFrameDescriptor
private void readFrameDescriptor() throws java.io.IOException- Throws:
java.io.IOException
-
nextBlock
private void nextBlock() throws java.io.IOException- Throws:
java.io.IOException
-
maybeFinishCurrentBlock
private void maybeFinishCurrentBlock() throws java.io.IOException- Throws:
java.io.IOException
-
verifyContentChecksum
private void verifyContentChecksum() throws java.io.IOException- Throws:
java.io.IOException
-
verifyChecksum
private void verifyChecksum(XXHash32 hash, java.lang.String kind) throws java.io.IOException
- Throws:
java.io.IOException
-
readOneByte
private int readOneByte() throws java.io.IOException- Throws:
java.io.IOException
-
readOnce
private int readOnce(byte[] b, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
isSkippableFrameSignature
private static boolean isSkippableFrameSignature(byte[] b)
-
skipSkippableFrame
private int skipSkippableFrame(byte[] b) throws java.io.IOExceptionSkips over the contents of a skippable frame as well as skippable frames following it.It then tries to read four more bytes which are supposed to hold an LZ4 signature and returns the number of bytes read while storing the bytes in the given array.
- Throws:
java.io.IOException
-
appendToBlockDependencyBuffer
private void appendToBlockDependencyBuffer(byte[] b, int off, int len)
-
matches
public static boolean matches(byte[] signature, int length)Checks if the signature matches what is expected for a .lz4 file..lz4 files start with a four byte signature.
- Parameters:
signature- the bytes to checklength- the number of bytes to check- Returns:
- true if this is a .sz stream, false otherwise
-
-