public class InflaterInputStream extends FilterInputStream
FilterInputStream
that
decompresses data that was compressed using the DEFLATE algorithm
(see specification).
Basically it wraps the Inflater
class and takes care of the
buffering.Inflater
,
DeflaterOutputStream
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
The input buffer used for decompression.
|
protected Inflater |
inf
The inflater used for this stream.
|
protected int |
len
The length of the buffer.
|
in
Constructor and Description |
---|
InflaterInputStream(InputStream is)
This is the most basic constructor.
|
InflaterInputStream(InputStream is,
Inflater inflater)
This constructor lets you pass a specifically initialized Inflater,
for example one that expects no ZLIB header.
|
InflaterInputStream(InputStream is,
Inflater inflater,
int bsize)
This constructor lets you specify both the
Inflater as well as
the internal buffer size to be used. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns 0 when when this stream has exhausted its input; and 1 otherwise.
|
void |
close()
Closes the input stream.
|
protected void |
fill()
Fills the input buffer with data to be decompressed.
|
void |
mark(int readlimit)
Marks the current position in the stream.
|
boolean |
markSupported()
Returns whether the receiver implements
mark semantics. |
int |
read()
Reads a single byte of decompressed data.
|
int |
read(byte[] buffer,
int offset,
int byteCount)
Reads up to
byteCount bytes of decompressed data and stores it in
buffer starting at offset . |
void |
reset()
Reset the position of the stream to the last marked position.
|
long |
skip(long byteCount)
Skips up to
byteCount bytes of uncompressed data. |
read
protected Inflater inf
protected byte[] buf
protected int len
public InflaterInputStream(InputStream is)
InputStream
from which the compressed data is to be read from. Default
settings for the Inflater
and internal buffer are be used. In
particular the Inflater expects a ZLIB header from the input stream.is
- the InputStream
to read data from.public InflaterInputStream(InputStream is, Inflater inflater)
is
- the InputStream
to read data from.inflater
- the specific Inflater
for decompressing data.public InflaterInputStream(InputStream is, Inflater inflater, int bsize)
Inflater
as well as
the internal buffer size to be used.is
- the InputStream
to read data from.inflater
- the specific Inflater
for decompressing data.bsize
- the size to be used for the internal buffer.public int read() throws IOException
read
in class FilterInputStream
IOException
- if an error occurs reading the byte.public int read(byte[] buffer, int offset, int byteCount) throws IOException
byteCount
bytes of decompressed data and stores it in
buffer
starting at offset
.read
in class FilterInputStream
buffer
- the byte array in which to store the bytes read.offset
- the initial position in buffer
to store the bytes
read from this stream.byteCount
- the maximum number of bytes to store in buffer
.IOException
- if this stream is closed or another I/O error occurs.protected void fill() throws IOException
IOException
- if an IOException
occurs.public long skip(long byteCount) throws IOException
byteCount
bytes of uncompressed data.skip
in class FilterInputStream
byteCount
- the number of bytes to skip.IllegalArgumentException
- if byteCount < 0
.IOException
- if an error occurs skipping.FilterInputStream.mark(int)
,
FilterInputStream.reset()
public int available() throws IOException
Although consistent with the RI, this behavior is inconsistent with
InputStream.available()
, and violates the Liskov
Substitution Principle. This method should not be used.
available
in class FilterInputStream
IOException
- if this stream is closed or an error occurspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterInputStream
IOException
- If an error occurs closing the input stream.public void mark(int readlimit)
mark
in class FilterInputStream
readlimit
- of no use.FilterInputStream.markSupported()
,
FilterInputStream.reset()
public void reset() throws IOException
IOException
when called.reset
in class FilterInputStream
IOException
- if the method is calledFilterInputStream.mark(int)
,
FilterInputStream.markSupported()
public boolean markSupported()
mark
semantics. This type
does not support mark()
, so always responds false
.markSupported
in class FilterInputStream
FilterInputStream.mark(int)
,
FilterInputStream.reset()
,
FilterInputStream.skip(long)