Package net.jpountz.lz4
Class LZ4FrameInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- net.jpountz.lz4.LZ4FrameInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class LZ4FrameInputStream extends java.io.FilterInputStream
Implementation of the v1.5.1 LZ4 Frame format. This class is NOT thread safe.Not Supported:
- Dependent blocks
- Legacy streams
Originally based on kafka's KafkaLZ4BlockInputStream.
- See Also:
- LZ4 Framing Format Spec 1.5.1
-
-
Constructor Summary
Constructors Constructor Description LZ4FrameInputStream(java.io.InputStream in)
Creates a newInputStream
that will decompress data using fastest instances ofLZ4SafeDecompressor
andXXHash32
.LZ4FrameInputStream(java.io.InputStream in, boolean readSingleFrame)
Creates a newInputStream
that will decompress data using fastest instances ofLZ4SafeDecompressor
andXXHash32
.LZ4FrameInputStream(java.io.InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum)
Creates a newInputStream
that will decompress data using the LZ4 algorithm.LZ4FrameInputStream(java.io.InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum, boolean readSingleFrame)
Creates a newInputStream
that will decompress data using the LZ4 algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
long
getExpectedContentSize()
Returns the optional Content Size value set in Frame Descriptor.boolean
isExpectedContentSizeDefined()
Checks if the optionnal Content Size is set (FLG.Bits.CONTENT_SIZE is enabled).void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b, int off, int len)
void
reset()
long
skip(long n)
-
-
-
Constructor Detail
-
LZ4FrameInputStream
public LZ4FrameInputStream(java.io.InputStream in) throws java.io.IOException
Creates a newInputStream
that will decompress data using fastest instances ofLZ4SafeDecompressor
andXXHash32
. This instance will decompress all concatenated frames in their sequential order.- Parameters:
in
- the stream to decompress- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32)
,LZ4Factory.fastestInstance()
,XXHashFactory.fastestInstance()
-
LZ4FrameInputStream
public LZ4FrameInputStream(java.io.InputStream in, boolean readSingleFrame) throws java.io.IOException
Creates a newInputStream
that will decompress data using fastest instances ofLZ4SafeDecompressor
andXXHash32
.- Parameters:
in
- the stream to decompressreadSingleFrame
- whether read is stopped after the first non-skippable frame- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32)
,LZ4Factory.fastestInstance()
,XXHashFactory.fastestInstance()
-
LZ4FrameInputStream
public LZ4FrameInputStream(java.io.InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum) throws java.io.IOException
Creates a newInputStream
that will decompress data using the LZ4 algorithm. This instance will decompress all concatenated frames in their sequential order.- Parameters:
in
- the stream to decompressdecompressor
- the decompressor to usechecksum
- the hash function to use- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean)
-
LZ4FrameInputStream
public LZ4FrameInputStream(java.io.InputStream in, LZ4SafeDecompressor decompressor, XXHash32 checksum, boolean readSingleFrame) throws java.io.IOException
Creates a newInputStream
that will decompress data using the LZ4 algorithm.- Parameters:
in
- the stream to decompressdecompressor
- the decompressor to usechecksum
- the hash function to usereadSingleFrame
- whether read is stopped after the first non-skippable frame- Throws:
java.io.IOException
- if an I/O error occurs
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classjava.io.FilterInputStream
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.FilterInputStream
-
getExpectedContentSize
public long getExpectedContentSize() throws java.io.IOException
Returns the optional Content Size value set in Frame Descriptor. If the Content Size is not set (FLG.Bits.CONTENT_SIZE not enabled) in compressed stream, -1L is returned. A call to this method is valid only when this instance is supposed to read only one frame (readSingleFrame == true).- Returns:
- the expected content size, or -1L if no expected content size is set in the frame.
- Throws:
java.io.IOException
- On input stream read exception- See Also:
LZ4FrameInputStream(InputStream, LZ4SafeDecompressor, XXHash32, boolean)
-
isExpectedContentSizeDefined
public boolean isExpectedContentSizeDefined() throws java.io.IOException
Checks if the optionnal Content Size is set (FLG.Bits.CONTENT_SIZE is enabled).- Returns:
- true if this instance is supposed to read only one frame and if the optional content size is set in the frame.
- Throws:
java.io.IOException
- On input stream read exception
-
-