classes are a little raw for
easy digestion. It would be more convenient to write uncompressed
data onto an output stream and have it compressed by the stream
itself, without having to worry about the mechanics of deflation.
Similarly, it would be useful to have an input stream class that
could read from a compressed file but return the uncompressed data.
Java, in fact, has several classes that do exactly this. The
java.util.zip.DeflaterOutputStream class is a
filter stream that compresses the data it receives in deflated format
before writing it out to the underlying stream. The
java.util.zip.InflaterInputStream class inflates
deflated data before passing it to the reading program.
java.util.zip.GZIPOutputStream do the same thing
except with the gzip format.
is a filter stream that deflates data
before writing it onto the underlying stream:
public class DeflaterOutputStream extends FilterOutputStream
Each stream uses a protected
def to compress data stored in a protected
internal buffer called
protected Deflater def; protected byte buf;
The same deflater must not be used in multiple streams at the same time, though Java takes no steps to guarantee this.
The underlying output stream that receives the deflated data, the
def, and the length of the byte
buf are all set by one of the three ...