Class FramedLZ4CompressorInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.compress.compressors.CompressorInputStream
org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorInputStream
- All Implemented Interfaces:
Closeable,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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final int(package private) static final intprivate byte[]private final XXHash32(package private) static final int(package private) static final intprivate final XXHash32private InputStreamprivate final booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate final CountingInputStreamprivate boolean(package private) static final byte[]private final byte[]private static final byteprivate static final byte[]private final ByteUtils.ByteSupplier(package private) static final int(package private) static final int(package private) static final int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new input stream that decompresses streams compressed using the LZ4 frame format and stops after decompressing the first frame.FramedLZ4CompressorInputStream(InputStream in, boolean decompressConcatenated) Creates a new input stream that decompresses streams compressed using the LZ4 frame format. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendToBlockDependencyBuffer(byte[] b, int off, int len) voidclose()longGets the amount of raw or compressed bytes read by the stream.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 voidprivate voidintread()intread(byte[] b, int off, int len) private voidprivate intreadOnce(byte[] b, int off, int len) private intprivate 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, String kind) private voidMethods inherited from class org.apache.commons.compress.compressors.CompressorInputStream
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytesMethods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skipMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.compress.utils.InputStreamStatistics
getUncompressedCount
-
Field Details
-
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:
-
VERSION_MASK
static final int VERSION_MASK- See Also:
-
SUPPORTED_VERSION
static final int SUPPORTED_VERSION- See Also:
-
BLOCK_INDEPENDENCE_MASK
static final int BLOCK_INDEPENDENCE_MASK- See Also:
-
BLOCK_CHECKSUM_MASK
static final int BLOCK_CHECKSUM_MASK- See Also:
-
CONTENT_SIZE_MASK
static final int CONTENT_SIZE_MASK- See Also:
-
CONTENT_CHECKSUM_MASK
static final int CONTENT_CHECKSUM_MASK- See Also:
-
BLOCK_MAX_SIZE_MASK
static final int BLOCK_MAX_SIZE_MASK- See Also:
-
UNCOMPRESSED_FLAG_MASK
static final int UNCOMPRESSED_FLAG_MASK- See Also:
-
oneByte
private final byte[] oneByte -
supplier
-
inputStream
-
decompressConcatenated
private final boolean decompressConcatenated -
expectBlockChecksum
private boolean expectBlockChecksum -
expectBlockDependency
private boolean expectBlockDependency -
expectContentSize
private boolean expectContentSize -
expectContentChecksum
private boolean expectContentChecksum -
currentBlock
-
endReached
private boolean endReached -
inUncompressed
private boolean inUncompressed -
contentHash
-
blockHash
-
blockDependencyBuffer
private byte[] blockDependencyBuffer
-
-
Constructor Details
-
FramedLZ4CompressorInputStream
Creates 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:
IOException- if reading fails
-
FramedLZ4CompressorInputStream
public FramedLZ4CompressorInputStream(InputStream in, boolean decompressConcatenated) throws IOException Creates 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:
IOException- if reading fails
-
-
Method Details
-
isSkippableFrameSignature
private static boolean isSkippableFrameSignature(byte[] b) -
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
-
appendToBlockDependencyBuffer
private void appendToBlockDependencyBuffer(byte[] b, int off, int len) -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getCompressedCount
public long getCompressedCount()Description copied from interface:InputStreamStatisticsGets the amount of raw or compressed bytes read by the stream.- Specified by:
getCompressedCountin interfaceInputStreamStatistics- Returns:
- the amount of raw or compressed bytes read by the stream.
- Since:
- 1.17
-
init
- Throws:
IOException
-
maybeFinishCurrentBlock
- Throws:
IOException
-
nextBlock
- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
readFrameDescriptor
- Throws:
IOException
-
readOnce
- Throws:
IOException
-
readOneByte
- Throws:
IOException
-
readSignature
- Throws:
IOException
-
skipSkippableFrame
Skips 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:
IOException
-
verifyChecksum
- Throws:
IOException
-
verifyContentChecksum
- Throws:
IOException
-