ec.util
Class CompressingOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
ec.util.CompressingOutputStream
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable
public class CompressingOutputStream
- extends java.util.zip.DeflaterOutputStream
CompressingInputStream and DecompressingOutputStream allow you to
perform compression on a stream, and flush it, and continue to use it.
This is useful if you're planning on compressing a stream socket.
Ordinarily compression does not send partial blocks across the stream
for efficiency's sake. That's not good because we want to use a stream
socket and the other side will just block waiting for a big chunk of data
that may take a long time to show up. This simulates the Z_PARTIAL_FLUSH
and Z_SYNC_FLUSH mechanisms in zlib. The code was largely stolen from
the comments at
http://developer.java.sun.com/developer/bugParade/bugs/4255743.html
http://developer.java.sun.com/developer/bugParade/bugs/4206909.html
Beware that, like other compression streams, you should NOT construct
multiple CompressingOutputStreams and attach them one by one to the same
underlying OutputStream, throwing each away one by one. This won't work.
Instread, construct one CompressingOutputStream wrapped around your
underlying OutputStream and just use that.
Fields inherited from class java.util.zip.DeflaterOutputStream |
buf, def |
Fields inherited from class java.io.FilterOutputStream |
out |
Method Summary |
void |
flush()
Insure all remaining data will be output. |
Methods inherited from class java.util.zip.DeflaterOutputStream |
close, deflate, finish, write, write |
Methods inherited from class java.io.FilterOutputStream |
write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CompressingOutputStream
public CompressingOutputStream(java.io.OutputStream output)
CompressingOutputStream
public CompressingOutputStream(java.io.OutputStream output,
int level,
boolean nowrap)
flush
public void flush()
throws java.io.IOException
- Insure all remaining data will be output.
- Specified by:
flush
in interface java.io.Flushable
- Overrides:
flush
in class java.io.FilterOutputStream
- Throws:
java.io.IOException