org.bolet.jgz
Class GZipOutputStream

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

public class GZipOutputStream
extends java.io.OutputStream

This class represents a stream which compress data into the gzip format, as specified in RFC 1952.

gzip streams contain meta-information in various fields, some of which being optional. This class class sets these fields to default, rather uninformative values: the OS field is set to 255 ("unknown"), the original file name is not included, and the original file modification time is set to 0. These values are legal, according to RFC 1952, and almost no application uses these fields anyway.

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

Since compression is inherently buffered, the provided stream needs not feature buffers.


Constructor Summary
GZipOutputStream(java.io.OutputStream out)
          Create the stream with the provided transport stream.
GZipOutputStream(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 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

GZipOutputStream

public GZipOutputStream(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

GZipOutputStream

public GZipOutputStream(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

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 gzip file are written on the transport stream (but the transport stream itself is not flushed). Note that gzip streams are made of several "members" and there is no indication that a member is the last. Hence, the receiver will need another way to decide whether this member is the last.

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

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