APIdia Launch Partner
Top Description Fields Constructors Methods
java.util.zip

public Class DeflaterOutputStream

extends FilterOutputStream
Class Inheritance
Known Direct Subclasses
java.util.zip.GZIPOutputStream, java.util.zip.ZipOutputStream
Imports
java.io.FilterOutputStream, .OutputStream, .InputStream, .IOException

This class implements an output stream filter for compressing data in the "deflate" compression format. It is also used as the basis for other types of compression filters, such as GZIPOutputStream.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

Compressor Usage

A DeflaterOutputStream created without specifying a compressor will create a compressor at construction time, and close the compressor when the output stream is closed.

If a compressor is specified when creating a DeflaterOutputStream, it is the responsibility of the caller to close the compressor after closing the output stream.

API Note

The close method should be called to release resources used by this stream, either directly, or with the try-with-resources statement.

Author
David Connelly
Since
1.1
See Also
Deflater

Field Summary

Modifier and TypeField and Description
protected byte[]
buf

Output buffer for writing compressed data.

private boolean
closed

Hides java.io.FilterOutputStream.closed.

Indicates that the stream has been closed.
protected Deflater
def

Compressor for this stream.

pack-priv static final int
private static final int
private final boolean
pack-priv boolean
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
DeflaterOutputStream(OutputStream
the output stream
out
,
Deflater
the compressor ("deflater")
def
,
int
the output buffer size
size
,
boolean
if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream
syncFlush
)

Creates a new output stream with the specified compressor, buffer size and flush mode.

public
DeflaterOutputStream(OutputStream
the output stream
out
,
Deflater
the compressor ("deflater")
def
,
int
the output buffer size
size
)

Creates a new output stream with the specified compressor and buffer size.

public
DeflaterOutputStream(OutputStream
the output stream
out
,
Deflater
the compressor ("deflater")
def
,
boolean
if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream
syncFlush
)

Creates a new output stream with the specified compressor, flush mode and a default buffer size.

public
DeflaterOutputStream(OutputStream
the output stream
out
,
Deflater
the compressor ("deflater")
def
)

Creates a new output stream with the specified compressor and a default buffer size.

public
DeflaterOutputStream(OutputStream
the output stream
out
,
boolean
if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream
syncFlush
)

Creates a new output stream and compressor with the default compression level, a default buffer size and the specified flush mode.

public
DeflaterOutputStream(OutputStream
the output stream
out
)

Creates a new output stream and compressor with the default compression level and a default buffer size.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Writes remaining compressed data to the output stream and closes the underlying stream.

protected void
deflate()

Writes next block of compressed data to the output stream.

public void
finish()

Finishes writing compressed data to the output stream without closing the underlying stream.

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes the compressed output stream.

public void
write(int
the byte to be written
b
)

Overrides java.io.FilterOutputStream.write.

Writes a byte to the compressed output stream.

public void
write(byte[]
the data to be written
b
,
int
the start offset of the data
off
,
int
the length of the data
len
)

Overrides java.io.FilterOutputStream.write.

Writes an array of bytes to the compressed output stream.

Inherited from java.io.FilterOutputStream:
write

Field Detail

bufback to summary
protected byte[] buf

Output buffer for writing compressed data.

closedback to summary
private boolean closed

Hides java.io.FilterOutputStream.closed.

Indicates that the stream has been closed.

defback to summary
protected Deflater def

Compressor for this stream.

DEFAULT_BUF_SIZEback to summary
pack-priv static final int DEFAULT_BUF_SIZE
SYNC_FLUSH_MIN_BUF_SIZEback to summary
private static final int SYNC_FLUSH_MIN_BUF_SIZE
syncFlushback to summary
private final boolean syncFlush
usesDefaultDeflaterback to summary
pack-priv boolean usesDefaultDeflater

Constructor Detail

DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out, Deflater def, int size, boolean syncFlush)

Creates a new output stream with the specified compressor, buffer size and flush mode.

Closing this output stream will not close the given compressor.

Parameters
out:OutputStream

the output stream

def:Deflater

the compressor ("deflater")

size:int

the output buffer size

syncFlush:boolean

if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream

Exceptions
IllegalArgumentException:
if size <= 0
Since
1.7
DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out, Deflater def, int size)

Creates a new output stream with the specified compressor and buffer size.

The new output stream instance is created as if by invoking the 4-argument constructor DeflaterOutputStream(out, def, size, false).

Closing this output stream will not close the given compressor.

Parameters
out:OutputStream

the output stream

def:Deflater

the compressor ("deflater")

size:int

the output buffer size

Exceptions
IllegalArgumentException:
if size <= 0
DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out, Deflater def, boolean syncFlush)

Creates a new output stream with the specified compressor, flush mode and a default buffer size.

Closing this output stream will not close the given compressor.

Parameters
out:OutputStream

the output stream

def:Deflater

the compressor ("deflater")

syncFlush:boolean

if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream

Since
1.7
DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out, Deflater def)

Creates a new output stream with the specified compressor and a default buffer size.

The new output stream instance is created as if by invoking the 3-argument constructor DeflaterOutputStream(out, def, false).

Closing this output stream will not close the given compressor.

Parameters
out:OutputStream

the output stream

def:Deflater

the compressor ("deflater")

DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out, boolean syncFlush)

Creates a new output stream and compressor with the default compression level, a default buffer size and the specified flush mode.

The compressor will be closed when this output stream is closed.

Parameters
out:OutputStream

the output stream

syncFlush:boolean

if true the flush() method of this instance flushes the compressor with flush mode Deflater#SYNC_FLUSH before flushing the output stream, otherwise only flushes the output stream

Since
1.7
DeflaterOutputStreamback to summary
public DeflaterOutputStream(OutputStream out)

Creates a new output stream and compressor with the default compression level and a default buffer size.

The new output stream instance is created as if by invoking the 2-argument constructor DeflaterOutputStream(out, false).

The compressor will be closed when this output stream is closed.

Parameters
out:OutputStream

the output stream

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Writes remaining compressed data to the output stream and closes the underlying stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error has occurred
deflateback to summary
protected void deflate() throws IOException

Writes next block of compressed data to the output stream.

Exceptions
IOException:
if an I/O error has occurred
finishback to summary
public void finish() throws IOException

Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream.

Exceptions
IOException:
if an I/O error has occurred
flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes the compressed output stream. If syncFlush is true when this compressed output stream is constructed, this method first flushes the underlying compressor with the flush mode Deflater#SYNC_FLUSH to force all pending data to be flushed out to the output stream and then flushes the output stream. Otherwise this method only flushes the output stream without flushing the compressor.

Annotations
@Override
Exceptions
IOException:
if an I/O error has occurred
Since
1.7
writeback to summary
public void write(int b) throws IOException

Overrides java.io.FilterOutputStream.write.

Writes a byte to the compressed output stream. This method will block until the byte can be written.

Parameters
b:int

the byte to be written

Annotations
@Override
Exceptions
IOException:
if an I/O error has occurred
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

Writes an array of bytes to the compressed output stream. This method will block until all the bytes are written.

Parameters
b:byte[]

the data to be written

off:int

the start offset of the data

len:int

the length of the data

Annotations
@Override
Exceptions
IOException:
if an I/O error has occurred