public class DeflaterOutputStream extends FilterOutputStream
FilterOutputStream that
compresses data using the DEFLATE algorithm. Basically it wraps the
Deflater class and takes care of the buffering.Deflater| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The buffer for the data to be written to.
|
protected Deflater |
def
The deflater used.
|
out| Constructor and Description |
|---|
DeflaterOutputStream(OutputStream os)
Constructs a new instance with a default-constructed
Deflater. |
DeflaterOutputStream(OutputStream os,
boolean syncFlush)
Constructs a new instance with the given flushing behavior (see
flush()). |
DeflaterOutputStream(OutputStream os,
Deflater def)
Constructs a new instance with the given
Deflater. |
DeflaterOutputStream(OutputStream os,
Deflater def,
boolean syncFlush)
Constructs a new instance with the given
Deflater and
flushing behavior (see flush()). |
DeflaterOutputStream(OutputStream os,
Deflater def,
int bufferSize)
Constructs a new instance with the given
Deflater and buffer size. |
DeflaterOutputStream(OutputStream os,
Deflater def,
int bufferSize,
boolean syncFlush)
Constructs a new instance with the given
Deflater, buffer size, and
flushing behavior (see flush()). |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Writes any unwritten compressed data to the underlying stream, the closes
all underlying streams.
|
protected void |
deflate()
Compress the data in the input buffer and write it to the underlying
stream.
|
void |
finish()
Writes any unwritten data to the underlying stream.
|
void |
flush()
Flushes the underlying stream.
|
void |
write(byte[] buffer,
int offset,
int byteCount)
Compresses
byteCount bytes of data from buf starting at
offset and writes it to the underlying stream. |
void |
write(int i)
Writes one byte to the target stream.
|
nullOutputStream, writeprotected byte[] buf
protected Deflater def
public DeflaterOutputStream(OutputStream os)
Deflater.public DeflaterOutputStream(OutputStream os, Deflater def)
Deflater.public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize)
Deflater and buffer size.public DeflaterOutputStream(OutputStream os, boolean syncFlush)
flush()).public DeflaterOutputStream(OutputStream os, Deflater def, boolean syncFlush)
Deflater and
flushing behavior (see flush()).public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize, boolean syncFlush)
Deflater, buffer size, and
flushing behavior (see flush()).protected void deflate()
throws IOException
IOException - If an error occurs during deflation.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FilterOutputStreamIOException - If an error occurs while closing the data compression
process.public void finish()
throws IOException
IOException - If an error occurs.public void write(int i)
throws IOException
FilterOutputStreamoneByte is written.write in class FilterOutputStreami - the byte to be written.IOException - if an I/O error occurs while writing to this stream.public void write(byte[] buffer,
int offset,
int byteCount)
throws IOException
byteCount bytes of data from buf starting at
offset and writes it to the underlying stream.write in class FilterOutputStreambuffer - the buffer to write.offset - the index of the first byte in buffer to write.byteCount - the number of bytes in buffer to write.IOException - If an error occurs during writing.public void flush()
throws IOException
For deflater output streams constructed with the syncFlush parameter set to true,
this first flushes all outstanding data so that it may be immediately read by its recipient.
Doing so may degrade compression but improve interactive behavior.
flush in interface Flushableflush in class FilterOutputStreamIOException - if an error occurs attempting to flush this stream.