ec.util
Class CompressingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
ec.util.CompressingInputStream
- All Implemented Interfaces:
- java.io.Closeable
public class CompressingInputStream
- extends java.util.zip.InflaterInputStream
CompressingInputStream and CompressingOutputStream 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 CompressingInputStreams and attach them one by one to the same
underlying InputStream, throwing each away one by one. This won't work.
Instread, construct one CompressingInputStream wrapped around your
underlying InputStream and just use that.
Fields inherited from class java.util.zip.InflaterInputStream |
buf, inf, len |
Fields inherited from class java.io.FilterInputStream |
in |
Method Summary |
int |
available()
available() should return the number of bytes that can be read without
running into blocking wait. |
Methods inherited from class java.util.zip.InflaterInputStream |
close, fill, mark, markSupported, read, read, reset, skip |
Methods inherited from class java.io.FilterInputStream |
read |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CompressingInputStream
public CompressingInputStream(java.io.InputStream in)
CompressingInputStream
public CompressingInputStream(java.io.InputStream in,
boolean nowrap)
available
public int available()
throws java.io.IOException
- available() should return the number of bytes that can be read without
running into blocking wait. Accomplishing this feast would eventually require
to pre-inflate a huge chunk of data, so we rather opt for a more relaxed
contract (java.util.zip.InflaterInputStream does not fit the bill).
This code has been tested to work with BufferedReader.readLine();
- Overrides:
available
in class java.util.zip.InflaterInputStream
- Throws:
java.io.IOException