Class DeflaterInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.DeflaterInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
Implements an input stream filter for compressing data in the "deflate"
compression format.
Compressor Usage
ADeflaterInputStream created without
specifying a compressor will create a compressor
at construction time, and close the compressor when the input stream
is closed.
If a compressor is specified when creating a DeflaterInputStream, it is the
responsibility of the caller to close the
compressor after closing the input stream.
- API Note:
- The
close()method should be called to release resources used by this stream, either directly, or with thetry-with-resources statement. - Since:
- 1.6
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]Input buffer for reading compressed data.protected final DeflaterCompressor for this stream.Fields declared in class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new input stream and compressor with the default compression level and a default buffer size.DeflaterInputStream(InputStream in, Deflater defl) Creates a new input stream with the specified compressor and a default buffer size.DeflaterInputStream(InputStream in, Deflater defl, int bufLen) Creates a new input stream with the specified compressor and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionintReturns 0 after EOF has been reached, otherwise always return 1.voidclose()Closes this input stream and its underlying input stream, discarding any pending uncompressed data.voidmark(int limit) This operation is not supported.booleanintread()Reads a single byte of compressed data from the input stream.intread(byte[] b, int off, int len) Reads compressed data into a byte array.voidreset()This operation is not supported.longskip(long n) Skips over and discards data from the input stream.Methods declared in class FilterInputStream
readModifier and TypeMethodDescriptionintread(byte[] b) Reads up tob.lengthbytes of data from this input stream into an array of bytes.Methods declared in class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToModifier and TypeMethodDescriptionstatic InputStreamReturns a newInputStreamthat reads no bytes.byte[]Reads all remaining bytes from the input stream.intreadNBytes(byte[] b, int off, int len) Reads the requested number of bytes from the input stream into the given byte array.byte[]readNBytes(int len) Reads up to a specified number of bytes from the input stream.voidskipNBytes(long n) Skips over and discards exactlynbytes of data from this input stream.longtransferTo(OutputStream out) Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Field Details
-
def
Compressor for this stream. -
buf
protected final byte[] bufInput buffer for reading compressed data.
-
-
Constructor Details
-
DeflaterInputStream
Creates a new input stream and compressor with the default compression level and a default buffer size.The compressor will be closed when this input stream is closed.
- Parameters:
in- input stream to read the uncompressed data to- Throws:
NullPointerException- ifinis null
-
DeflaterInputStream
Creates a new input stream with the specified compressor and a default buffer size.Closing this input stream will not close the given compressor.
- Parameters:
in- input stream to read the uncompressed data todefl- compressor ("deflater") for this stream- Throws:
NullPointerException- ifinordeflis null
-
DeflaterInputStream
Creates a new input stream with the specified compressor and buffer size.Closing this input stream will not close the given compressor.
- Parameters:
in- input stream to read the uncompressed data todefl- compressor ("deflater") for this streambufLen- compression buffer size- Throws:
IllegalArgumentException- ifbufLen <= 0NullPointerException- ifinordeflis null
-
-
Method Details
-
close
Closes this input stream and its underlying input stream, discarding any pending uncompressed data.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException- if an I/O error occurs- See Also:
-
read
Reads a single byte of compressed data from the input stream. This method will block until some input can be read and compressed.- Overrides:
readin classFilterInputStream- Returns:
- a single byte of compressed data, or -1 if the end of the uncompressed input stream is reached
- Throws:
IOException- if an I/O error occurs or if this stream is already closed- See Also:
-
read
Reads compressed data into a byte array. This method will block until some input can be read and compressed.- Overrides:
readin classFilterInputStream- Parameters:
b- buffer into which the data is readoff- starting offset of the data withinblen- maximum number of compressed bytes to read intob- Returns:
- the actual number of bytes read, or -1 if the end of the uncompressed input stream is reached
- Throws:
NullPointerException- ifbis nullIndexOutOfBoundsException- iflen > b.length - offIOException- if an I/O error occurs or if this input stream is already closed- See Also:
-
skip
Skips over and discards data from the input stream. This method may block until the specified number of bytes are skipped or end of stream is reached.- Overrides:
skipin classFilterInputStream- Implementation Note:
- This method skips at most
Integer.MAX_VALUEbytes. - Parameters:
n- number of bytes to be skipped. Ifnis zero then no bytes are skipped.- Returns:
- the actual number of bytes skipped, which might be zero
- Throws:
IOException- if an I/O error occurs or if this stream is already closedIllegalArgumentException- ifn < 0- See Also:
-
available
Returns 0 after EOF has been reached, otherwise always return 1.Programs should not count on this method to return the actual number of bytes that could be read without blocking
- Overrides:
availablein classFilterInputStream- Returns:
- zero after the end of the underlying input stream has been reached, otherwise always returns 1
- Throws:
IOException- if an I/O error occurs or if this stream is already closed
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classFilterInputStream- Returns:
- false, always
- See Also:
-
mark
public void mark(int limit) This operation is not supported.- Overrides:
markin classFilterInputStream- Parameters:
limit- maximum bytes that can be read before invalidating the position marker- See Also:
-
reset
This operation is not supported.- Overrides:
resetin classFilterInputStream- Throws:
IOException- always thrown- See Also:
-