public class

DeflaterOutputStream

extends FilterOutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ java.util.zip.DeflaterOutputStream
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

This class provides an implementation of FilterOutputStream that compresses data using the DEFLATE algorithm. Basically it wraps the Deflater class and takes care of the buffering.

See Also

Summary

Fields
protected byte[] buf The buffer for the data to be written to.
protected Deflater def The deflater used.
[Expand]
Inherited Fields
From class java.io.FilterOutputStream
Public Constructors
DeflaterOutputStream(OutputStream os, Deflater def)
This constructor lets you pass the Deflater specifying the compression algorithm.
DeflaterOutputStream(OutputStream os)
This is the most basic constructor.
DeflaterOutputStream(OutputStream os, Deflater def, int bsize)
This constructor lets you specify both the compression algorithm as well as the internal buffer size to be used.
Public Methods
void close()
Writes any unwritten compressed data to the underlying stream, the closes all underlying streams.
void finish()
Writes any unwritten data to the underlying stream.
void write(int i)
Writes one byte to the target stream.
void write(byte[] buffer, int off, int nbytes)
Compresses nbytes of data from buf starting at off and writes it to the underlying stream.
Protected Methods
void deflate()
Compress the data in the input buffer and write it to the underlying stream.
[Expand]
Inherited Methods
From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Fields

protected byte[] buf

Since: API Level 1

The buffer for the data to be written to.

protected Deflater def

Since: API Level 1

The deflater used.

Public Constructors

public DeflaterOutputStream (OutputStream os, Deflater def)

Since: API Level 1

This constructor lets you pass the Deflater specifying the compression algorithm.

Parameters
os is the OutputStream where to write the compressed data to.
def is the specific Deflater that is used to compress data.

public DeflaterOutputStream (OutputStream os)

Since: API Level 1

This is the most basic constructor. You only need to pass the OutputStream to which the compressed data shall be written to. The default settings for the Deflater and internal buffer are used. In particular the Deflater produces a ZLIB header in the output stream.

Parameters
os is the OutputStream where to write the compressed data to.

public DeflaterOutputStream (OutputStream os, Deflater def, int bsize)

Since: API Level 1

This constructor lets you specify both the compression algorithm as well as the internal buffer size to be used.

Parameters
os is the OutputStream where to write the compressed data to.
def is the specific Deflater that will be used to compress data.
bsize is the size to be used for the internal buffer.

Public Methods

public void close ()

Since: API Level 1

Writes any unwritten compressed data to the underlying stream, the closes all underlying streams. This stream can no longer be used after close() has been called.

Throws
IOException If an error occurs while closing the data compression process.

public void finish ()

Since: API Level 1

Writes any unwritten data to the underlying stream. Does not close the stream.

Throws
IOException If an error occurs.

public void write (int i)

Since: API Level 1

Writes one byte to the target stream. Only the low order byte of the integer oneByte is written.

Parameters
i the byte to be written.
Throws
IOException

public void write (byte[] buffer, int off, int nbytes)

Since: API Level 1

Compresses nbytes of data from buf starting at off and writes it to the underlying stream.

Parameters
buffer the buffer of data to compress.
off offset in buffer to extract data from.
nbytes the number of bytes of data to read from the buffer.
Throws
IOException If an error occurs during writing.

Protected Methods

protected void deflate ()

Since: API Level 1

Compress the data in the input buffer and write it to the underlying stream.

Throws
IOException If an error occurs during deflation.