ec.util
Class CompressingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
ec.util.CompressingInputStream
- 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
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, read, read, skip |
Methods inherited from class java.io.FilterInputStream |
mark, markSupported, read, reset |
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();
- Throws:
java.io.IOException