deflate algorithm, and then a trailer.
This class is capable of reading a stream consisting of a series of members.
Reading from the stream may read and buffer bytes from the underlying stream. This includes bytes that follow a member's trailer. Whether or not any additional bytes have been read past a member's trailer, the read methods on this class yield decompressed data from at most one member; data from multiple members is not combined in a single read operation.
GZIPInputStream is not safe for use by multiple concurrent threads. Any multithreaded
concurrent use must be guarded by appropriate synchronization.
API Note
The close method should be called to release resources used by this
stream, either directly, or with the try-with-resources statement.
Implementation Note
After reading a member trailer, the read method calls
InputStream#available() on the underlying stream to determine whether additional
bytes are available that may represent a subsequent member. If the
jdk.util.gzip.tryReadAheadAfterTrailer system property is set
to true, then the call to InputStream.available() is skipped and the
implementation instead attempts to read a subsequent member in the stream.
GZIPInputStream depends on the return value of InputStream.available()
to reliably process a stream with a series of members. Consequently, it may be necessary
to set this property in environments that process streams with a series of members. By default,
the jdk.util.gzip.tryReadAheadAfterTrailer system property is not set, and
InputStream.available() gets called.
InflaterInputStream
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean | |
| private boolean | |
| protected CRC32 | crc
CRC-32 for decompressed data. |
| protected boolean | eos
Indicates end of input stream. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| public static final int | GZIP_MAGIC
GZIP header magic number. |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| public | GZIPInputStream(InputStream
the input stream in, int the input buffer size size)Creates a new input stream with the specified buffer size. |
| public | GZIPInputStream(InputStream
the input stream in)Creates a new input stream with a default buffer size. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
| private static Inflater | |
| private void | ensureOpen()
Hides java. Check to make sure that this stream has not been closed |
| private boolean | hasNoMoreMembers()
Reads the current GZIP member's trailer and returns true if the end-of-stream is reached. |
| public int | Returns: the actual number of bytes decompressed from a GZIP member, or -1 if the end-of-stream is reachedthe buffer into which the data is read buf, int the start offset in the destination array off, int bufthe maximum number of bytes to read into len)bufOverrides java. Reads decompressed data into an array of bytes, returning the number of decompressed bytes. |
| private int | |
| private void | readTrailer(final InputStream
the InputStream containing the trailer stream)Reads the current member's trailer |
| private int | |
| private long | |
| private int | |
| private void |
| alwaysReadNextMember | back to summary |
|---|---|
| private static final boolean alwaysReadNextMember | |
| closed | back to summary |
|---|---|
| private boolean closed | |
| crc | back to summary |
|---|---|
| protected CRC32 crc CRC-32 for decompressed data. | |
| eos | back to summary |
|---|---|
| protected boolean eos Indicates end of input stream. | |
| FCOMMENT | back to summary |
|---|---|
| private static final int FCOMMENT | |
| FEXTRA | back to summary |
|---|---|
| private static final int FEXTRA | |
| FHCRC | back to summary |
|---|---|
| private static final int FHCRC | |
| FNAME | back to summary |
|---|---|
| private static final int FNAME | |
| GZIP_MAGIC | back to summary |
|---|---|
| public static final int GZIP_MAGIC GZIP header magic number. | |
| tmpbuf | back to summary |
|---|---|
| private final byte[] tmpbuf | |
| GZIPInputStream | back to summary |
|---|---|
| public GZIPInputStream(InputStream in, int size) throws IOException Creates a new input stream with the specified buffer size.
| |
| GZIPInputStream | back to summary |
|---|---|
| public GZIPInputStream(InputStream in) throws IOException Creates a new input stream with a default buffer size.
| |
| checkUnexpectedByte | back to summary |
|---|---|
| private void checkUnexpectedByte(final int b) throws IOException | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream.
| |
| createInflater | back to summary |
|---|---|
| private static Inflater createInflater(InputStream in, int size) | |
| ensureOpen | back to summary |
|---|---|
| private void ensureOpen() throws IOException Hides java. Check to make sure that this stream has not been closed | |
| hasNoMoreMembers | back to summary |
|---|---|
| private boolean hasNoMoreMembers() throws IOException Reads the current GZIP member's trailer and returns true if the end-of-stream is reached. After reading the current member's trailer, if the stream has a subsequent GZIP member, then this method reads that member's header and returns false indicating that there is another member in the stream. | |
| read | back to summary |
|---|---|
| public int read(byte[] buf, int off, int len) throws IOException Overrides java. Reads decompressed data into an array of bytes, returning the number of decompressed
bytes. If
If this method returns a nonzero integer n then
| |
| readHeader | back to summary |
|---|---|
| private int readHeader(InputStream stream, boolean failOnEOF) throws IOException | |
| readTrailer | back to summary |
|---|---|
| private void readTrailer(final InputStream stream) throws IOException Reads the current member's trailer
| |
| readUByte | back to summary |
|---|---|
| private int readUByte(InputStream in) throws IOException | |
| readUInt | back to summary |
|---|---|
| private long readUInt(InputStream in) throws IOException | |
| readUShort | back to summary |
|---|---|
| private int readUShort(InputStream in) throws IOException | |
| skipBytes | back to summary |
|---|---|
| private void skipBytes(InputStream in, int n) throws IOException | |