public class DeflaterInputStream extends FilterInputStream
InputStream
filter to compress data. Callers read
compressed data in the "deflate" format from the uncompressed
underlying stream.Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf |
protected Deflater |
def |
in
Constructor and Description |
---|
DeflaterInputStream(InputStream in)
Constructs a
DeflaterInputStream with a new Deflater and an
implementation-defined default internal buffer size. |
DeflaterInputStream(InputStream in,
Deflater deflater)
Constructs a
DeflaterInputStream with the given Deflater and an
implementation-defined default internal buffer size. |
DeflaterInputStream(InputStream in,
Deflater deflater,
int bufferSize)
Constructs a
DeflaterInputStream with the given Deflater and
given internal buffer size. |
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 underlying input stream and discards any remaining uncompressed
data.
|
void |
mark(int limit)
This operation is not supported and does nothing.
|
boolean |
markSupported()
Returns false because
DeflaterInputStream does not support
mark /reset . |
int |
read()
Reads a byte from the compressed input stream.
|
int |
read(byte[] buffer,
int offset,
int byteCount)
Reads compressed data into a byte buffer.
|
void |
reset()
This operation is not supported and throws
IOException . |
long |
skip(long byteCount)
Skips
byteCount bytes in this stream. |
read
protected final Deflater def
protected final byte[] buf
public DeflaterInputStream(InputStream in)
DeflaterInputStream
with a new Deflater
and an
implementation-defined default internal buffer size. in
is a source of
uncompressed data, and this stream will be a source of compressed data.in
- the source InputStream
public DeflaterInputStream(InputStream in, Deflater deflater)
DeflaterInputStream
with the given Deflater
and an
implementation-defined default internal buffer size. in
is a source of
uncompressed data, and this stream will be a source of compressed data.in
- the source InputStream
deflater
- the Deflater
to be used for compressionpublic DeflaterInputStream(InputStream in, Deflater deflater, int bufferSize)
DeflaterInputStream
with the given Deflater
and
given internal buffer size. in
is a source of
uncompressed data, and this stream will be a source of compressed data.in
- the source InputStream
deflater
- the Deflater
to be used for compressionbufferSize
- the length in bytes of the internal bufferpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterInputStream
IOException
- if an error occurs while closing this stream.public int read() throws IOException
read
in class FilterInputStream
IOException
- if the stream is closed or another IOException occurs.public int read(byte[] buffer, int offset, int byteCount) throws IOException
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.public long skip(long byteCount) throws IOException
byteCount
bytes in this stream. Subsequent
calls to read
will not return these bytes unless reset
is
used. This implementation skips byteCount
bytes in the
filtered stream.
Note: if n > Integer.MAX_VALUE
, this stream will only attempt to
skip Integer.MAX_VALUE
bytes.
skip
in class FilterInputStream
byteCount
- the number of bytes to skip.IOException
- if this stream is closed or another IOException occurs.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 boolean markSupported()
DeflaterInputStream
does not support
mark
/reset
.markSupported
in class FilterInputStream
true
if mark()
and reset()
are supported,
false
otherwise.FilterInputStream.mark(int)
,
FilterInputStream.reset()
,
FilterInputStream.skip(long)
public void mark(int limit)
mark
in class FilterInputStream
limit
- the number of bytes that can be read from this stream before
the mark is invalidated.FilterInputStream.markSupported()
,
FilterInputStream.reset()
public void reset() throws IOException
IOException
.reset
in class FilterInputStream
IOException
- if this stream is already closed, no mark has been set or the
mark is no longer valid because more than readlimit
bytes have been read since setting the mark.FilterInputStream.mark(int)
,
FilterInputStream.markSupported()