Package java.util.zip
Class DeflaterOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
GZIPOutputStream,ZipOutputStream
public class DeflaterOutputStream extends FilterOutputStream
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:
Deflater
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufThe buffer for the data to be written to.protected DeflaterdefThe deflater used.Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors Constructor Description DeflaterOutputStream(OutputStream os)Constructs a new instance with a default-constructedDeflater.DeflaterOutputStream(OutputStream os, boolean syncFlush)Constructs a new instance with the given flushing behavior (seeflush()).DeflaterOutputStream(OutputStream os, Deflater def)Constructs a new instance with the givenDeflater.DeflaterOutputStream(OutputStream os, Deflater def, boolean syncFlush)Constructs a new instance with the givenDeflaterand flushing behavior (seeflush()).DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize)Constructs a new instance with the givenDeflaterand buffer size.DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize, boolean syncFlush)Constructs a new instance with the givenDeflater, buffer size, and flushing behavior (seeflush()). -
Method Summary
Modifier and Type Method Description voidclose()Writes any unwritten compressed data to the underlying stream, the closes all underlying streams.protected voiddeflate()Compress the data in the input buffer and write it to the underlying stream.voidfinish()Writes any unwritten data to the underlying stream.voidflush()Flushes the underlying stream.voidwrite(byte[] buffer, int offset, int byteCount)CompressesbyteCountbytes of data frombufstarting atoffsetand writes it to the underlying stream.voidwrite(int i)Writes one byte to the target stream.Methods inherited from class java.io.OutputStream
write
-
Field Details
-
buf
protected byte[] bufThe buffer for the data to be written to. -
def
The deflater used.
-
-
Constructor Details
-
DeflaterOutputStream
Constructs a new instance with a default-constructedDeflater. -
DeflaterOutputStream
Constructs a new instance with the givenDeflater. -
DeflaterOutputStream
Constructs a new instance with the givenDeflaterand buffer size. -
DeflaterOutputStream
Constructs a new instance with the given flushing behavior (seeflush()).- Since:
- 1.7
-
DeflaterOutputStream
Constructs a new instance with the givenDeflaterand flushing behavior (seeflush()).- Since:
- 1.7
-
DeflaterOutputStream
Constructs a new instance with the givenDeflater, buffer size, and flushing behavior (seeflush()).- Since:
- 1.7
-
-
Method Details
-
deflate
Compress the data in the input buffer and write it to the underlying stream.- Throws:
IOException- If an error occurs during deflation.
-
close
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.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException- If an error occurs while closing the data compression process.
-
finish
Writes any unwritten data to the underlying stream. Does not close the stream.- Throws:
IOException- If an error occurs.
-
write
Description copied from class:FilterOutputStreamWrites one byte to the target stream. Only the low order byte of the integeroneByteis written.- Overrides:
writein classFilterOutputStream- Parameters:
i- the byte to be written.- Throws:
IOException- if an I/O error occurs while writing to this stream.
-
write
CompressesbyteCountbytes of data frombufstarting atoffsetand writes it to the underlying stream.- Overrides:
writein classFilterOutputStream- Parameters:
buffer- the buffer to write.offset- the index of the first byte inbufferto write.byteCount- the number of bytes inbufferto write.- Throws:
IOException- If an error occurs during writing.
-
flush
Flushes the underlying stream. This flushes only the bytes that can be compressed at the highest level.For deflater output streams constructed with the
syncFlushparameter 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.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException- if an error occurs attempting to flush this stream.
-