Class GZIPInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
java.util.zip.GZIPInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
This class implements a stream filter for reading compressed data in
the GZIP file format.
- Since:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CRC32CRC-32 for uncompressed data.protected booleanIndicates end of input stream.static final intGZIP header magic number.Fields inherited from class InflaterInputStream
buf, inf, lenFields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new input stream with a default buffer size.GZIPInputStream(InputStream in, int size) Creates a new input stream with the specified buffer size. -
Method Summary
Methods inherited from class InflaterInputStream
available, fill, mark, markSupported, read, reset, skipModifier and TypeMethodDescriptionintReturns 0 after EOF has been reached, otherwise always return 1.protected voidfill()Fills input buffer with more data to decompress.voidmark(int readlimit) Marks the current position in this input stream.booleanTests if this input stream supports themarkandresetmethods.intread()Reads a byte of uncompressed data.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.longskip(long n) Skips specified number of bytes of uncompressed data.Methods inherited from class FilterInputStream
readModifier and TypeMethodDescriptionintread(byte[] b) Reads up tob.lengthbytes of data from this input stream into an array of bytes.Methods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToModifier and TypeMethodDescriptionstatic InputStreamReturns a newInputStreamthat reads no bytes.byte[]Reads all remaining bytes from the input stream.intreadNBytes(byte[] b, int off, int len) Reads the requested number of bytes from the input stream into the given byte array.byte[]readNBytes(int len) Reads up to a specified number of bytes from the input stream.voidskipNBytes(long n) Skips over and discards exactlynbytes of data from this input stream.longtransferTo(OutputStream out) Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Field Details
-
crc
CRC-32 for uncompressed data. -
eos
protected boolean eosIndicates end of input stream. -
GZIP_MAGIC
public static final int GZIP_MAGICGZIP header magic number.- See Also:
-
-
Constructor Details
-
GZIPInputStream
Creates a new input stream with the specified buffer size.- Parameters:
in- the input streamsize- the input buffer size- Throws:
ZipException- if a GZIP format error has occurred or the compression method used is unsupportedNullPointerException- ifinis nullIOException- if an I/O error has occurredIllegalArgumentException- ifsize <= 0
-
GZIPInputStream
Creates a new input stream with a default buffer size.- Parameters:
in- the input stream- Throws:
ZipException- if a GZIP format error has occurred or the compression method used is unsupportedNullPointerException- ifinis nullIOException- if an I/O error has occurred
-
-
Method Details
-
read
Reads uncompressed data into an array of bytes, returning the number of inflated bytes. Iflenis not zero, the method will block until some input can be decompressed; otherwise, no bytes are read and0is returned.If this method returns a nonzero integer n then
buf[off]throughbuf[off+n-1]contain the uncompressed data. The content of elementsbuf[off+n]throughbuf[off+len-1]is undefined, contrary to the specification of theInputStreamsuperclass, so an implementation is free to modify these elements during the inflate operation. If this method returns-1or throws an exception then the content ofbuf[off]throughbuf[off+len-1]is undefined.- Overrides:
readin classInflaterInputStream- Parameters:
buf- the buffer into which the data is readoff- the start offset in the destination arraybuflen- the maximum number of bytes read- Returns:
- the actual number of bytes inflated, or -1 if the end of the compressed input stream is reached
- Throws:
NullPointerException- Ifbufisnull.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanbuf.length - offZipException- if the compressed input data is corrupt.IOException- if an I/O error has occurred.- See Also:
-
close
Closes this input stream and releases any system resources associated with the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInflaterInputStream- Throws:
IOException- if an I/O error has occurred- See Also:
-