Class Overview
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();
}
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. |
Public Methods |
void
|
close()
Closes this stream and any underlying streams.
|
int
|
read(byte[] buffer, int offset, int byteCount)
Reads and decompresses GZIP data from the underlying stream into the
given buffer.
|
[Expand]
Inherited Methods |
From class
java.util.zip.InflaterInputStream
|
From class
java.io.FilterInputStream
|
From class
java.io.InputStream
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Called before the object's memory is reclaimed by the VM.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes the object and release any system resources it holds.
|
|
Constants
public
static
final
int
GZIP_MAGIC
The magic header for the GZIP format.
Constant Value:
35615
(0x00008b1f)
Fields
protected
CRC32
crc
The checksum algorithm used when handling uncompressed data.
protected
boolean
eos
Indicates the end of the input stream.
Public Constructors
public
GZIPInputStream
(InputStream is)
Construct a GZIPInputStream
to read from GZIP data from the
underlying stream.
Parameters
is
| the InputStream to read data from. |
public
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
| the InputStream to read data from. |
size
| the internal read buffer size. |
Public Methods
public
void
close
()
Closes this stream and any underlying streams.
public
int
read
(byte[] buffer, int offset, int byteCount)
Reads and decompresses GZIP data from the underlying stream into the
given buffer.
Parameters
buffer
| the byte array in which to store the bytes read. |
offset
| the initial position in buffer to store the bytes
read from this stream. |
byteCount
| the maximum number of bytes to store in buffer . |
Returns
- Number of uncompressed bytes read