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
An
InputStream filter to compress data. Callers read
compressed data in the "deflate" format from the uncompressed
underlying stream.- Since:
- 1.6
-
Field Summary
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
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 Details
-
def
-
buf
protected final byte[] buf
-
-
Constructor Details
-
DeflaterInputStream
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
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
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 Details
-
close
Closes 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
Reads 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
Reads 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
SkipsbyteCountbytes 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- Parameters:
byteCount- the number of bytes to skip.- 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
Returns 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
This 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()
-