Package java.util.zip
Class DeflaterInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.util.zip.DeflaterInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class DeflaterInputStream extends FilterInputStream
AnInputStreamfilter to compress data. Callers read compressed data in the "deflate" format from the uncompressed underlying stream.- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufprotected Deflaterdef-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description DeflaterInputStream(InputStream in)Constructs aDeflaterInputStreamwith a newDeflaterand an implementation-defined default internal buffer size.DeflaterInputStream(InputStream in, Deflater deflater)Constructs aDeflaterInputStreamwith the givenDeflaterand an implementation-defined default internal buffer size.DeflaterInputStream(InputStream in, Deflater deflater, int bufferSize)Constructs aDeflaterInputStreamwith the givenDeflaterand given internal buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns 0 when when this stream has exhausted its input; and 1 otherwise.voidclose()Closes the underlying input stream and discards any remaining uncompressed data.voidmark(int limit)This operation is not supported and does nothing.booleanmarkSupported()Returns false becauseDeflaterInputStreamdoes not supportmark/reset.intread()Reads a byte from the compressed input stream.intread(byte[] buffer, int byteOffset, int byteCount)Reads up tobyteCountbytes of compressed data into a byte buffer.voidreset()This operation is not supported and throwsIOException.longskip(long byteCount)SkipsbyteCountbytes in this stream.-
Methods inherited from class java.io.InputStream
read
-
-
-
-
Field Detail
-
def
protected final Deflater def
-
buf
protected final byte[] buf
-
-
Constructor Detail
-
DeflaterInputStream
public DeflaterInputStream(InputStream in)
Constructs aDeflaterInputStreamwith a newDeflaterand an implementation-defined default internal buffer size.inis a source of uncompressed data, and this stream will be a source of compressed data.- Parameters:
in- the sourceInputStream
-
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater deflater)
Constructs aDeflaterInputStreamwith the givenDeflaterand an implementation-defined default internal buffer size.inis a source of uncompressed data, and this stream will be a source of compressed data.- Parameters:
in- the sourceInputStreamdeflater- theDeflaterto be used for compression
-
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater deflater, int bufferSize)
Constructs aDeflaterInputStreamwith the givenDeflaterand given internal buffer size.inis a source of uncompressed data, and this stream will be a source of compressed data.- Parameters:
in- the sourceInputStreamdeflater- theDeflaterto be used for compressionbufferSize- the length in bytes of the internal buffer
-
-
Method Detail
-
close
public void close() throws IOExceptionCloses the underlying input stream and discards any remaining uncompressed data.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException- if an error occurs while closing this stream.
-
read
public int read() throws IOExceptionReads a byte from the compressed input stream. The result will be a byte of compressed data corresponding to an uncompressed byte or bytes read from the underlying stream.- Overrides:
readin classFilterInputStream- Returns:
- the byte or -1 if the end of the stream has been reached.
- Throws:
IOException- if the stream is closed or another IOException occurs.
-
read
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOExceptionReads up tobyteCountbytes of compressed data into a byte buffer. The result will be bytes of compressed data corresponding to an uncompressed byte or bytes read from the underlying stream. Returns the number of bytes read or -1 if the end of the compressed input stream has been reached.- Overrides:
readin classFilterInputStream- Throws:
IOException- if the stream is closed or another IOException occurs.
-
skip
public long skip(long byteCount) throws IOExceptionSkipsbyteCountbytes in this stream. Subsequent calls toreadwill not return these bytes unlessresetis used. This implementation skipsbyteCountbytes in the filtered stream.Note: if
n > Integer.MAX_VALUE, this stream will only attempt to skipInteger.MAX_VALUEbytes.- Overrides:
skipin classFilterInputStream- Returns:
- the number of bytes actually skipped.
- Throws:
IOException- if this stream is closed or another IOException occurs.- See Also:
FilterInputStream.mark(int),FilterInputStream.reset()
-
available
public int available() throws IOExceptionReturns 0 when when this stream has exhausted its input; and 1 otherwise. A result of 1 does not guarantee that further bytes can be returned, with or without blocking.Although consistent with the RI, this behavior is inconsistent with
InputStream.available(), and violates the Liskov Substitution Principle. This method should not be used.- Overrides:
availablein classFilterInputStream- Returns:
- 0 if no further bytes are available. Otherwise returns 1, which suggests (but does not guarantee) that additional bytes are available.
- Throws:
IOException- if this stream is closed or an error occurs
-
markSupported
public boolean markSupported()
Returns false becauseDeflaterInputStreamdoes not supportmark/reset.- Overrides:
markSupportedin classFilterInputStream- Returns:
trueifmark()andreset()are supported,falseotherwise.- See Also:
FilterInputStream.mark(int),FilterInputStream.reset(),FilterInputStream.skip(long)
-
mark
public void mark(int limit)
This operation is not supported and does nothing.- Overrides:
markin classFilterInputStream- Parameters:
limit- the number of bytes that can be read from this stream before the mark is invalidated.- See Also:
FilterInputStream.markSupported(),FilterInputStream.reset()
-
reset
public void reset() throws IOExceptionThis operation is not supported and throwsIOException.- Overrides:
resetin classFilterInputStream- Throws:
IOException- if this stream is already closed, no mark has been set or the mark is no longer valid because more thanreadlimitbytes have been read since setting the mark.- See Also:
FilterInputStream.mark(int),FilterInputStream.markSupported()
-
-