Class CompressingInputStream

  extended by
      extended by
          extended by
              extended by ec.util.CompressingInputStream
All Implemented Interfaces:

public class CompressingInputStream

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

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.

Field Summary
Fields inherited from class
buf, inf, len
Fields inherited from class
Constructor Summary
CompressingInputStream( in)
CompressingInputStream( in, boolean nowrap)
Method Summary
 int available()
          available() should return the number of bytes that can be read without running into blocking wait.
Methods inherited from class
close, fill, mark, markSupported, read, read, reset, skip
Methods inherited from class
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CompressingInputStream( in)


public CompressingInputStream( in,
                              boolean nowrap)
Method Detail


public int available()
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 ( does not fit the bill). This code has been tested to work with BufferedReader.readLine();

available in class