org.bolet.jgz
Class ZlibOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.bolet.jgz.ZlibOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class ZlibOutputStream
extends java.io.OutputStream

This class implements a stream which compresses data into the zlib format (RFC 1950).

The compression level can be specified, as a symbolic value identical to what the Deflater class expects. The default compression level is MEDIUM.


Constructor Summary
ZlibOutputStream(java.io.OutputStream out)
          Create the stream with the provided transport stream.
ZlibOutputStream(java.io.OutputStream out, int level)
          Create the stream with the provided transport stream.
 
Method Summary
 void close()
          Close this stream; the transport stream is also closed.
 void flush()
          Flush this stream; the transport stream is also flushed.
 void flushFull(boolean withData)
          Flush this stream; the transport stream is also flushed.
 void flushPartial()
          Flush this stream; the transport stream is also flushed.
 void flushSync(boolean withData)
          Flush this stream; the transport stream is also flushed.
 void processDictionary(byte[] dict)
          Process a dictionary: the buffer contents are used as dictionary.
 void processDictionary(byte[] dict, int off, int len)
          Process a dictionary: the buffer contents are used as dictionary.
 void processDictionary(java.io.InputStream dict)
          Process a dictionary: the stream contents are used as dictionary.
 void terminate()
          Close the compression stream but do not close the transport stream.
 void write(byte[] buf)
           
 void write(byte[] buf, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZlibOutputStream

public ZlibOutputStream(java.io.OutputStream out)
                 throws java.io.IOException
Create the stream with the provided transport stream. The default compression level (MEDIUM) is used.

Parameters:
out - the transport stream
Throws:
java.io.IOException - on I/O error with the transport stream

ZlibOutputStream

public ZlibOutputStream(java.io.OutputStream out,
                        int level)
                 throws java.io.IOException
Create the stream with the provided transport stream. The provided compression level is used.

Parameters:
out - the transport stream
level - the compression level
Throws:
java.io.IOException - on I/O error with the transport stream
Method Detail

processDictionary

public void processDictionary(java.io.InputStream dict)
                       throws java.io.IOException
Process a dictionary: the stream contents are used as dictionary.

Parameters:
dict - the dictionary stream
Throws:
java.io.IOException - on I/O error with dict

processDictionary

public void processDictionary(byte[] dict)
Process a dictionary: the buffer contents are used as dictionary.

Parameters:
dict - the dictionary

processDictionary

public void processDictionary(byte[] dict,
                              int off,
                              int len)
Process a dictionary: the buffer contents are used as dictionary.

Parameters:
dict - the dictionary
off - the dictionary offset
len - the dictionary length

close

public void close()
           throws java.io.IOException
Close this stream; the transport stream is also closed.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - on I/O error with the transport stream

terminate

public void terminate()
               throws java.io.IOException
Close the compression stream but do not close the transport stream. All bytes which constitute the zlib file are written on the transport stream (but the transport stream itself is not flushed).

Throws:
java.io.IOException - on I/O error with the transport stream

flush

public void flush()
           throws java.io.IOException
Flush this stream; the transport stream is also flushed. At the DEFLATE level, a "sync flush" is performed, which ensures that output bytes written so far on the transport stream are sufficient to recover all the input bytes currently processed.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - on I/O error with the transport stream

flushSync

public void flushSync(boolean withData)
               throws java.io.IOException
Flush this stream; the transport stream is also flushed. At the DEFLATE level, a "sync flush" is performed, with the provided value for withData.

Parameters:
withData - false to omit the 00 00 FF FF bytes
Throws:
java.io.IOException - on I/O error with the transport stream

flushFull

public void flushFull(boolean withData)
               throws java.io.IOException
Flush this stream; the transport stream is also flushed. At the DEFLATE level, a "full flush" is performed, with the provided value for withData.

Parameters:
withData - false to omit the 00 00 FF FF bytes
Throws:
java.io.IOException - on I/O error with the transport stream

flushPartial

public void flushPartial()
                  throws java.io.IOException
Flush this stream; the transport stream is also flushed. At the DEFLATE level, a "partial flush" is performed.

Throws:
java.io.IOException - on I/O error with the transport stream

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream

write

public void write(byte[] buf)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream