public class GZIPInputStream extends InflaterInputStream
GZIPInputStream class is used to read data stored in the GZIP
format, reading and decompressing GZIP data from the underlying stream into
its buffer.
Using GZIPInputStream is easier than ZipInputStream
because GZIP is only for compression, and is not a container for multiple files.
This code decompresses the data from a GZIP stream, similar to the gunzip(1) utility.
InputStream is = ...
GZIPInputStream zis = new GZIPInputStream(new BufferedInputStream(is));
try {
// Reading from 'zis' gets you the uncompressed bytes...
processStream(zis);
} finally {
zis.close();
}
Note that this class ignores all remaining data at the end of the last GZIP member.
| Modifier and Type | Field and Description |
|---|---|
protected CRC32 |
crc
The checksum algorithm used when handling uncompressed data.
|
protected boolean |
eos
Indicates the end of the input stream.
|
static int |
GZIP_MAGIC
The magic header for the GZIP format.
|
buf, inf, lenin| Constructor and Description |
|---|
GZIPInputStream(InputStream is)
Construct a
GZIPInputStream to read from GZIP data from the
underlying stream. |
GZIPInputStream(InputStream is,
int size)
Construct a
GZIPInputStream to read from GZIP data from the
underlying stream. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this stream and any underlying streams.
|
int |
read(byte[] buffer,
int byteOffset,
int byteCount)
Reads up to
byteCount bytes of decompressed data and stores it in
buffer starting at byteOffset. |
available, fill, mark, markSupported, read, reset, skipnullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTopublic static final int GZIP_MAGIC
protected CRC32 crc
protected boolean eos
public GZIPInputStream(InputStream is) throws IOException
GZIPInputStream to read from GZIP data from the
underlying stream.is - the InputStream to read data from.IOException - if an IOException occurs.public GZIPInputStream(InputStream is, int size) throws IOException
GZIPInputStream to read from GZIP data from the
underlying stream. Set the internal buffer size to size.is - the InputStream to read data from.size - the internal read buffer size.IOException - if an IOException occurs.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InflaterInputStreamIOException - If an error occurs closing the input stream.public int read(byte[] buffer,
int byteOffset,
int byteCount)
throws IOException
InflaterInputStreambyteCount bytes of decompressed data and stores it in
buffer starting at byteOffset. Returns the number of uncompressed bytes read,
or -1.read in class InflaterInputStreamIOException - if the stream is closed or another IOException occurs.