com.jcraft.jzlib
Class ZInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.jcraft.jzlib.ZInputStream
All Implemented Interfaces:
Closeable

public class ZInputStream
extends FilterInputStream

An output stream wrapper around a ZStream. This can work either as a deflating or inflating stream, depending on the constructor being used.


Field Summary
protected  byte[] buf
          The internal buffer used for reading the original stream and passing input to the ZStream.
protected  byte[] buf1
          A one-byte buffer, used by read().
protected  int bufsize
          The size of our internal buffer buf.
protected  boolean compress
          Wether we are inflating (false) or deflating (true).
protected  int flush
          The flushing mode in use.
protected  InputStream in
          The source input stream.
protected  ZStream z
          The wrapped ZStream, which does the work.
 
Constructor Summary
ZInputStream(InputStream in)
          Creates a new decompressing (inflating) ZInputStream reading zlib formatted data.
ZInputStream(InputStream in, boolean nowrap)
          Creates a new decompressing (inflating) ZInputStream, reading either zlib or plain deflate data.
ZInputStream(InputStream in, int level)
          Creates a compressing (deflating) ZInputStream, producing zlib format data.
 
Method Summary
 void close()
          Closes this stream.
 int getFlushMode()
          Returns the current flush mode used for each compressing/decompressing call.
 long getTotalIn()
          Returns the total number of bytes input so far.
 long getTotalOut()
          Returns the total number of bytes output so far.
 int read()
          Reads one byte of data.
 int read(byte[] b, int off, int len)
          reads some data from the stream.
 void setFlushMode(int flush)
          Returns the current flush mode used for each compressing/decompressing call.
 long skip(long n)
          skips some amount of (compressed or decompressed) input.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

z

protected ZStream z
The wrapped ZStream, which does the work.


bufsize

protected int bufsize
The size of our internal buffer buf.


flush

protected int flush
The flushing mode in use.


buf

protected byte[] buf
The internal buffer used for reading the original stream and passing input to the ZStream.


buf1

protected byte[] buf1
A one-byte buffer, used by read().


compress

protected boolean compress
Wether we are inflating (false) or deflating (true).


in

protected InputStream in
The source input stream. The data will be read from this before being compressed or decompressed.

Constructor Detail

ZInputStream

public ZInputStream(InputStream in)
Creates a new decompressing (inflating) ZInputStream reading zlib formatted data.

Parameters:
in - the base stream, which should contain data in zlib format.

ZInputStream

public ZInputStream(InputStream in,
                    boolean nowrap)
Creates a new decompressing (inflating) ZInputStream, reading either zlib or plain deflate data.

Parameters:
in - the base stream, which should contain data in the right format.
nowrap - if true, the input is plain deflate data. If false, it is in zlib format (i.e. with a small header and a checksum).

ZInputStream

public ZInputStream(InputStream in,
                    int level)
Creates a compressing (deflating) ZInputStream, producing zlib format data. The stream reads uncompressed data from the base stream, and produces compressed data in zlib format.

Parameters:
in - the base stream from which to read uncompressed data.
level - the compression level which will be used.
Method Detail

read

public int read()
         throws IOException
Reads one byte of data.

Overrides:
read in class FilterInputStream
Returns:
the read byte, or -1 on end of input.
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
reads some data from the stream. This will compress or decompress data from the underlying stream.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer in which to put the data.
off - the offset in b on which we should put the data.
len - how much data to read maximally.
Returns:
the amount of data actually read.
Throws:
IOException

skip

public long skip(long n)
          throws IOException
skips some amount of (compressed or decompressed) input. In this implementation, we will simply read some data and discard it. We will skip maximally 512 bytes on each call.

Overrides:
skip in class FilterInputStream
Returns:
the number of bytes actually skipped.
Throws:
IOException

getFlushMode

public int getFlushMode()
Returns the current flush mode used for each compressing/decompressing call. Normally this should be Z_NO_FLUSH.


setFlushMode

public void setFlushMode(int flush)
Returns the current flush mode used for each compressing/decompressing call. Normally this should be Z_NO_FLUSH.


getTotalIn

public long getTotalIn()
Returns the total number of bytes input so far.


getTotalOut

public long getTotalOut()
Returns the total number of bytes output so far.


close

public void close()
           throws IOException
Closes this stream. This closes the underlying stream, too.

Specified by:
close in interface Closeable
Overrides:
close in class FilterInputStream
Throws:
IOException


This is an inofficial Javadoc created by PaĆ­lo Ebermann. Have a look at the official homepage.