Skip to content

Most visited

Recently visited

navigation
Added in API level 1

GZIPInputStream

public class GZIPInputStream
extends InflaterInputStream

java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.util.zip.InflaterInputStream
         ↳ java.util.zip.GZIPInputStream


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();
 }
 

Note that this class ignores all remaining data at the end of the last GZIP member.

Summary

Constants

int GZIP_MAGIC

The magic header for the GZIP format.

Fields

protected CRC32 crc

The checksum algorithm used when handling uncompressed data.

protected boolean eos

Indicates the end of the input stream.

Inherited fields

From class java.util.zip.InflaterInputStream
From class java.io.FilterInputStream

Public constructors

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.

Public methods

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.

Inherited methods

From class java.util.zip.InflaterInputStream
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

GZIP_MAGIC

Added in API level 1
int GZIP_MAGIC

The magic header for the GZIP format.

Constant Value: 35615 (0x00008b1f)

Fields

crc

Added in API level 1
CRC32 crc

The checksum algorithm used when handling uncompressed data.

eos

Added in API level 1
boolean eos

Indicates the end of the input stream.

Public constructors

GZIPInputStream

Added in API level 1
GZIPInputStream (InputStream is)

Construct a GZIPInputStream to read from GZIP data from the underlying stream.

Parameters
is InputStream: the InputStream to read data from.
Throws
IOException if an IOException occurs.

GZIPInputStream

Added in API level 1
GZIPInputStream (InputStream is, 
                int size)

Construct a GZIPInputStream to read from GZIP data from the underlying stream. Set the internal buffer size to size.

Parameters
is InputStream: the InputStream to read data from.
size int: the internal read buffer size.
Throws
IOException if an IOException occurs.

Public methods

close

Added in API level 1
void close ()

Closes this stream and any underlying streams.

Throws
IOException

read

Added in API level 1
int read (byte[] buffer, 
                int byteOffset, 
                int byteCount)

Reads up to byteCount bytes of decompressed data and stores it in buffer starting at byteOffset. Returns the number of uncompressed bytes read, or -1.

Parameters
buffer byte
byteOffset int
byteCount int
Returns
int
Throws
IOException
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.