de.enough.polish.util.zip
Class GZipInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by de.enough.polish.util.zip.GZipInputStream
All Implemented Interfaces:
Closeable

public class GZipInputStream
extends InputStream

Reads and uncompresses GZIP or DEFLATE encoded input streams.

Copyright Enough Software 2007 - 2010

 history
        Jun 25, 2007 - Simon creation
 

Author:
Simon Schmitt, simon.schmitt@enough.de

Field Summary
static int TYPE_DEFLATE
          This constant triggers the normal deflate compression as described in rfc 1951.
static int TYPE_GZIP
          This constant triggers the gzip compression that is the same as deflate with some extra header information (see rfc 1952).
 
Constructor Summary
GZipInputStream(InputStream inputStream, int compressionType, boolean hash)
          Creates an input stream capable of GZIP and Deflate with a buffer of 1024 bytes.
GZipInputStream(InputStream inputStream, int size, int compressionType, boolean hash)
          Creates an input stream capable of GZIP and Deflate.
 
Method Summary
 int available()
          This function fills the buffer and returns the amount of avialable data.
 void close()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 long skip(long n)
           
 int validData()
          Checks if the current status is valid
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_DEFLATE

public static final int TYPE_DEFLATE
This constant triggers the normal deflate compression as described in rfc 1951.

See Also:
Constant Field Values

TYPE_GZIP

public static final int TYPE_GZIP
This constant triggers the gzip compression that is the same as deflate with some extra header information (see rfc 1952).

See Also:
Constant Field Values
Constructor Detail

GZipInputStream

public GZipInputStream(InputStream inputStream,
                       int compressionType,
                       boolean hash)
                throws IOException
Creates an input stream capable of GZIP and Deflate with a buffer of 1024 bytes.

Parameters:
inputStream - the stream that contains the compressed data.
compressionType - TYPE_GZIP or TYPE_DEFLATE
hash - set true for data checking, set false for speed reading
Throws:
IOException - when the header of a GZIP stream cannot be skipped
See Also:
TYPE_DEFLATE, TYPE_GZIP

GZipInputStream

public GZipInputStream(InputStream inputStream,
                       int size,
                       int compressionType,
                       boolean hash)
                throws IOException
Creates an input stream capable of GZIP and Deflate.

Parameters:
inputStream - the stream that contains the compressed data.
size - the size of the internally used buffer
compressionType - TYPE_GZIP or TYPE_DEFLATE
hash - set true for data checking, set false for speed reading
Throws:
IOException - when the header of a GZIP stream cannot be skipped
See Also:
TYPE_DEFLATE, TYPE_GZIP
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

validData

public int validData()
              throws IOException
Checks if the current status is valid

Returns:
-1 if the stream is finished, 1 if the current data is valid, 0 if not
Throws:
IOException

available

public int available()
              throws IOException
This function fills the buffer and returns the amount of avialable data. Therefore it will always return the buffer size that was given to the constructor.

Overrides:
available in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException