com.jcraft.jzlib
Class ZOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.jcraft.jzlib.ZOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class ZOutputStream
extends OutputStream

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
           
protected  byte[] buf1
          A one-byte buffer, used by write(int).
protected  int bufsize
           
protected  boolean compress
           
protected  int flush
           
protected  OutputStream out
          The underlying output stream.
protected  ZStream z
           
 
Constructor Summary
ZOutputStream(OutputStream out)
          Creates a new decompressing (inflating) ZOutputStream.
ZOutputStream(OutputStream out, int level)
          Creates a new compressing (deflating) ZOutputStream.
ZOutputStream(OutputStream out, int level, boolean nowrap)
          Creates a new compressing (deflating) ZOutputStream.
 
Method Summary
 void close()
          Closes the stream.
 void end()
          Cleans up the deflater/inflater state.
 void finish()
          Finishes the compressing/decompressing, without closing the underlying stream.
 void flush()
          flushes the underlying stream.
 int getFlushMode()
          Returns the current flush mode, which will be used for every write(int).
 long getTotalIn()
          Returns the total number of bytes input so far.
 long getTotalOut()
          Returns the total number of bytes output so far.
 void setFlushMode(int flush)
          Sets the flush mode.
 void write(byte[] b, int off, int len)
          Writes a sequence of bytes, compressing or decompressing it.
 void write(int b)
          Writes a single byte.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

z

protected ZStream z

bufsize

protected int bufsize

flush

protected int flush

buf

protected byte[] buf

buf1

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


compress

protected boolean compress

out

protected OutputStream out
The underlying output stream. All compressed (or decompressed) data will be written to this.

Constructor Detail

ZOutputStream

public ZOutputStream(OutputStream out)
Creates a new decompressing (inflating) ZOutputStream. The stream expects the written data to be in zlib format, and writes the decompressed data to the argument stream.


ZOutputStream

public ZOutputStream(OutputStream out,
                     int level)
Creates a new compressing (deflating) ZOutputStream. The stream will compress any written data, and write it to the argument stream in zlib format.

Parameters:
out - the stream that will receive the compressed data.
level - the deflation level. This should be Z_NO_COMPRESSION, Z_DEFAULT_COMPRESSION or a value between Z_BEST_SPEED (1) and Z_BEST_COMPRESSION (9) (both inclusive).

ZOutputStream

public ZOutputStream(OutputStream out,
                     int level,
                     boolean nowrap)
Creates a new compressing (deflating) ZOutputStream. The stream will compress any written data, and write it to the argument stream in either zlib or plain deflate format.

Parameters:
out - the stream that will receive the compressed data.
level - the deflation level. This should be Z_NO_COMPRESSION, Z_DEFAULT_COMPRESSION or a value between Z_BEST_SPEED (1) and Z_BEST_COMPRESSION (9) (both inclusive).
nowrap - if true, the stream uses the plain deflate format. If false, the stream uses the zlib format (which includes a header and checksum).
Method Detail

write

public void write(int b)
           throws IOException
Writes a single byte. This is a shortcut to calling write(new byte[]{b},0,1) (but reusing the array for multiple calls).

Specified by:
write in class OutputStream
Parameters:
b - the byte to write.
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes a sequence of bytes, compressing or decompressing it.

Overrides:
write in class OutputStream
Parameters:
b - the array holding the data
off - the offset in b where the data starts.
len - the length of the data.
Throws:
IOException

getFlushMode

public int getFlushMode()
Returns the current flush mode, which will be used for every write(int).


setFlushMode

public void setFlushMode(int flush)
Sets the flush mode. This will be used for every write(int).


finish

public void finish()
            throws IOException
Finishes the compressing/decompressing, without closing the underlying stream. This will flush the buffer, end the block and (if not in plain deflate mode) add or compare the checksum.

Throws:
IOException

end

public void end()
Cleans up the deflater/inflater state. This will be automatically called by close().


close

public void close()
           throws IOException
Closes the stream. This will flush out anything written so far, release any resources, and close the underlying stream, too.

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

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.


flush

public void flush()
           throws IOException
flushes the underlying stream.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException


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