Package java.util.zip
Class InflaterInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
GZIPInputStream,ZipInputStream
public class InflaterInputStream extends FilterInputStream
This class provides an implementation of
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.- See Also:
Inflater,DeflaterOutputStream
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufThe input buffer used for decompression.protected InflaterinfThe inflater used for this stream.protected intlenThe length of the buffer.Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors Constructor 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 bufferSize)This constructor lets you specify both theInflateras well as the internal buffer size to be used. -
Method Summary
Modifier and Type Method Description intavailable()Returns 0 when when this stream has exhausted its input; and 1 otherwise.voidclose()Closes the input stream.protected voidfill()Fills the input buffer with data to be decompressed.voidmark(int readlimit)Marks the current position in the stream.booleanmarkSupported()Returns whether the receiver implementsmarksemantics.intread()Reads a single byte of decompressed data.intread(byte[] buffer, int byteOffset, int byteCount)Reads up tobyteCountbytes of decompressed data and stores it inbufferstarting atbyteOffset.voidreset()Reset the position of the stream to the last marked position.longskip(long byteCount)Skips up tobyteCountbytes of uncompressed data.Methods inherited from class java.io.InputStream
read
-
Field Details
-
inf
The inflater used for this stream. -
buf
protected byte[] bufThe input buffer used for decompression. -
len
protected int lenThe length of the buffer.
-
-
Constructor Details
-
InflaterInputStream
This is the most basic constructor. You only need to pass theInputStreamfrom which the compressed data is to be read from. Default settings for theInflaterand internal buffer are be used. In particular the Inflater expects a ZLIB header from the input stream.- Parameters:
is- theInputStreamto read data from.
-
InflaterInputStream
This constructor lets you pass a specifically initialized Inflater, for example one that expects no ZLIB header.- Parameters:
is- theInputStreamto read data from.inflater- the specificInflaterfor decompressing data.
-
InflaterInputStream
This constructor lets you specify both theInflateras well as the internal buffer size to be used.- Parameters:
is- theInputStreamto read data from.inflater- the specificInflaterfor decompressing data.bufferSize- the size to be used for the internal buffer.
-
-
Method Details
-
read
Reads a single byte of decompressed data.- Overrides:
readin classFilterInputStream- Returns:
- the byte read.
- Throws:
IOException- if an error occurs reading the byte.
-
read
Reads up tobyteCountbytes of decompressed data and stores it inbufferstarting atbyteOffset. Returns the number of uncompressed bytes read, or -1.- Overrides:
readin classFilterInputStream- Throws:
IOException- if the stream is closed or another IOException occurs.
-
fill
Fills the input buffer with data to be decompressed.- Throws:
IOException- if anIOExceptionoccurs.
-
skip
Skips up tobyteCountbytes of uncompressed data.- Overrides:
skipin classFilterInputStream- Parameters:
byteCount- the number of bytes to skip.- Returns:
- the number of uncompressed bytes skipped.
- Throws:
IllegalArgumentException- ifbyteCount < 0.IOException- if an error occurs skipping.- See Also:
FilterInputStream.mark(int),FilterInputStream.reset()
-
available
Returns 0 when when this stream has exhausted its input; and 1 otherwise. A result of 1 does not guarantee that further bytes can be returned, with or without blocking.Although consistent with the RI, this behavior is inconsistent with
InputStream.available(), and violates the Liskov Substitution Principle. This method should not be used.- Overrides:
availablein classFilterInputStream- Returns:
- 0 if no further bytes are available. Otherwise returns 1, which suggests (but does not guarantee) that additional bytes are available.
- Throws:
IOException- if this stream is closed or an error occurs
-
close
Closes the input stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException- If an error occurs closing the input stream.
-
mark
public void mark(int readlimit)Marks the current position in the stream. This implementation overrides the super type implementation to do nothing at all.- Overrides:
markin classFilterInputStream- Parameters:
readlimit- of no use.- See Also:
FilterInputStream.markSupported(),FilterInputStream.reset()
-
reset
Reset the position of the stream to the last marked position. This implementation overrides the supertype implementation and always throws anIOExceptionwhen called.- Overrides:
resetin classFilterInputStream- Throws:
IOException- if the method is called- See Also:
FilterInputStream.mark(int),FilterInputStream.markSupported()
-
markSupported
public boolean markSupported()Returns whether the receiver implementsmarksemantics. This type does not supportmark(), so always respondsfalse.- Overrides:
markSupportedin classFilterInputStream- Returns:
- false, always
- See Also:
FilterInputStream.mark(int),FilterInputStream.reset(),FilterInputStream.skip(long)
-