Package java.util.zip
Class GZIPInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
java.util.zip.GZIPInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
public class GZIPInputStream extends InflaterInputStream
The
GZIPInputStream class is used to read data stored in the GZIP
format, reading and decompressing GZIP data from the underlying stream into
its buffer.
Example
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();
}
-
Field Summary
Fields Modifier and Type Field Description protected CRC32crcThe checksum algorithm used when handling uncompressed data.protected booleaneosIndicates the end of the input stream.static intGZIP_MAGICThe magic header for the GZIP format.Fields inherited from class java.util.zip.InflaterInputStream
buf, inf, lenFields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors Constructor Description GZIPInputStream(InputStream is)Construct aGZIPInputStreamto read from GZIP data from the underlying stream.GZIPInputStream(InputStream is, int size)Construct aGZIPInputStreamto read from GZIP data from the underlying stream. -
Method Summary
Methods inherited from class java.util.zip.InflaterInputStream
available, fill, mark, markSupported, read, reset, skipMethods inherited from class java.io.InputStream
read
-
Field Details
-
GZIP_MAGIC
public static final int GZIP_MAGICThe magic header for the GZIP format.- See Also:
- Constant Field Values
-
crc
The checksum algorithm used when handling uncompressed data. -
eos
protected boolean eosIndicates the end of the input stream.
-
-
Constructor Details
-
GZIPInputStream
Construct aGZIPInputStreamto read from GZIP data from the underlying stream.- Parameters:
is- theInputStreamto read data from.- Throws:
IOException- if anIOExceptionoccurs.
-
GZIPInputStream
Construct aGZIPInputStreamto read from GZIP data from the underlying stream. Set the internal buffer size tosize.- Parameters:
is- theInputStreamto read data from.size- the internal read buffer size.- Throws:
IOException- if anIOExceptionoccurs.
-
-
Method Details
-
close
Closes this stream and any underlying streams.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInflaterInputStream- Throws:
IOException- If an error occurs closing the input stream.
-
read
Description copied from class:InflaterInputStreamReads up tobyteCountbytes of decompressed data and stores it inbufferstarting atbyteOffset. Returns the number of uncompressed bytes read, or -1.- Overrides:
readin classInflaterInputStream- Throws:
IOException- if the stream is closed or another IOException occurs.
-