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
TheGZIPInputStreamclass is used to read data stored in the GZIP format, reading and decompressing GZIP data from the underlying stream into its buffer.Example
Using
GZIPInputStreamis easier thanZipInputStreambecause GZIP is only for compression, and is not a container for multiple files. This code decompresses the data from a GZIP stream, similar to thegunzip(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.
-
-
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, len
-
Fields 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this stream and any underlying streams.intread(byte[] buffer, int byteOffset, int byteCount)Reads up tobyteCountbytes of decompressed data and stores it inbufferstarting atbyteOffset.-
Methods inherited from class java.util.zip.InflaterInputStream
available, fill, mark, markSupported, read, reset, skip
-
Methods inherited from class java.io.InputStream
read
-
-
-
-
Field Detail
-
GZIP_MAGIC
public static final int GZIP_MAGIC
The magic header for the GZIP format.- See Also:
- Constant Field Values
-
crc
protected CRC32 crc
The checksum algorithm used when handling uncompressed data.
-
eos
protected boolean eos
Indicates the end of the input stream.
-
-
Constructor Detail
-
GZIPInputStream
public GZIPInputStream(InputStream is) throws IOException
Construct aGZIPInputStreamto read from GZIP data from the underlying stream.- Parameters:
is- theInputStreamto read data from.- Throws:
IOException- if anIOExceptionoccurs.
-
GZIPInputStream
public GZIPInputStream(InputStream is, int size) throws IOException
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 Detail
-
close
public void close() throws IOExceptionCloses 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
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOExceptionDescription 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.
-
-