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 ofFilterOutputStreamthat compresses data using the DEFLATE algorithm. Basically it wraps theDeflaterclass 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
All Methods Instance Methods Concrete Methods 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 Detail
-
buf
protected byte[] buf
The buffer for the data to be written to.
-
def
protected Deflater def
The deflater used.
-
-
Constructor Detail
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os)
Constructs a new instance with a default-constructedDeflater.
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os, Deflater def)
Constructs a new instance with the givenDeflater.
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize)
Constructs a new instance with the givenDeflaterand buffer size.
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os, boolean syncFlush)
Constructs a new instance with the given flushing behavior (seeflush()).- Since:
- 1.7
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os, Deflater def, boolean syncFlush)
Constructs a new instance with the givenDeflaterand flushing behavior (seeflush()).- Since:
- 1.7
-
DeflaterOutputStream
public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize, boolean syncFlush)
Constructs a new instance with the givenDeflater, buffer size, and flushing behavior (seeflush()).- Since:
- 1.7
-
-
Method Detail
-
deflate
protected void deflate() throws IOExceptionCompress the data in the input buffer and write it to the underlying stream.- Throws:
IOException- If an error occurs during deflation.
-
close
public void close() throws IOExceptionWrites 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
public void finish() throws IOExceptionWrites any unwritten data to the underlying stream. Does not close the stream.- Throws:
IOException- If an error occurs.
-
write
public void write(int i) throws IOExceptionDescription 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
public void write(byte[] buffer, int offset, int byteCount) throws IOExceptionCompressesbyteCountbytes 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
public void flush() throws IOExceptionFlushes 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.
-
-