Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

edu.emory.mathcs.util.io
Class CompressedOutputStream  view CompressedOutputStream download CompressedOutputStream.java

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended byedu.emory.mathcs.util.io.CompressedOutputStream

public class CompressedOutputStream
extends java.io.FilterOutputStream

Filter output stream that compresses data and features strong flush semantics. Data is written as gzipped packets of variable size. Flushing causes immediate ending of currently written packet and sending all the data off. Therefore, this stream can be used as a transport for RMI or RPC. Note that standard java.util.zip.ZipOutputStream and java.util.zip.GZipOutputStream are useless for this purpose due to their insufficiently strong flushing semantics: they don't guarantee that flush sends out all the data that was written so far, which leads to deadlocks in request-response-based protocols.

Compression ratio decreases with decreasing packet size. Hence, the gain will be low or none in RMI applications that exchange small chunks of data. Since the protocol adds two bytes of metadata per each packet, in the extreme case (flushing every single byte) the number of bytes actually sent is tripled. On the other hand, the compression ratio may be significant if large chunks are exchanged, e.g. if large arrays are sent as parameters or received as return values.

Version:
1.0

Field Summary
(package private)  byte[] buf
           
(package private) static short DEFLATED
           
(package private)  java.util.zip.Deflater deflater
           
(package private)  byte[] destbuf
           
(package private)  java.io.DataOutputStream dos
           
(package private)  int pos
           
(package private) static int STORE_TRESHOLD
           
(package private) static short STORED
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
CompressedOutputStream(java.io.OutputStream out)
           
CompressedOutputStream(java.io.OutputStream out, int bufSize)
           
 
Method Summary
 void flush()
          This method attempt to flush all buffered output to be written to the underlying output sink.
 void write(byte[] data, int off, int len)
          This method calls the write(int) method len times for all bytes from the array buf starting at index offset.
 void write(int b)
          This method writes a single byte of output to the underlying OutputStream.
private  void writePacket()
           
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFLATED

static final short DEFLATED
See Also:
Constant Field Values

STORED

static final short STORED
See Also:
Constant Field Values

STORE_TRESHOLD

static final int STORE_TRESHOLD
See Also:
Constant Field Values

buf

final byte[] buf

destbuf

final byte[] destbuf

dos

final java.io.DataOutputStream dos

pos

int pos

deflater

final java.util.zip.Deflater deflater
Constructor Detail

CompressedOutputStream

public CompressedOutputStream(java.io.OutputStream out)

CompressedOutputStream

public CompressedOutputStream(java.io.OutputStream out,
                              int bufSize)
Method Detail

write

public void write(int b)
           throws java.io.IOException
Description copied from class: java.io.FilterOutputStream
This method writes a single byte of output to the underlying OutputStream.


write

public void write(byte[] data,
                  int off,
                  int len)
           throws java.io.IOException
Description copied from class: java.io.FilterOutputStream
This method calls the write(int) method len times for all bytes from the array buf starting at index offset. Subclasses should overwrite this method to get a more efficient implementation.


flush

public void flush()
           throws java.io.IOException
Description copied from class: java.io.FilterOutputStream
This method attempt to flush all buffered output to be written to the underlying output sink.


writePacket

private void writePacket()
                  throws java.io.IOException