Package io.nayuki.deflate
Class InflaterInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
io.nayuki.deflate.InflaterInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Decompresses a DEFLATE data stream (raw format without zlib or gzip headers or footers) into a byte stream.
-
Constructor Summary
ConstructorDescriptionExtra constructor added for org.eclipse.mat.hprof Only safe to use copy or original once the underlying stream has been positioned to the appropriate location.InflaterInputStream
(InputStream in, boolean detachable) Constructs an inflater input stream over the specified underlying input stream, and with the specified option for detachability.InflaterInputStream
(InputStream in, boolean detachable, int inBufLen) Constructs an inflater input stream over the specified underlying input stream, with the specified options for detachability and input buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
attach()
Resume decompression.int
The number of bytes which can be read without blocking.void
close()
Closes this input stream and the underlying stream.void
detach()
Detaches the underlying input stream from this decompressor.void
mark
(int limit) Notes the current position of the output, so that later the caller can go back to this spot by calling reset.boolean
int
read()
Reads the next byte of decompressed data from this stream.int
read
(byte[] b, int off, int len) Reads some bytes from the decompressed data of this stream into the specified array's subrange.void
reset()
Goes back in the output to the point wheremark(int)
was called.long
skip
(long n) toString()
Methods inherited from class java.io.FilterInputStream
read
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
InflaterInputStream
Constructs an inflater input stream over the specified underlying input stream, and with the specified option for detachability. The underlying stream must contain DEFLATE-compressed data with no headers or footers (e.g. must be unwrapped from the zlib or gzip container formats). Detachability allowsdetach()
to be called, and requires the specified input stream to support marking.- Parameters:
in
- the underlying input stream of raw DEFLATE-compressed datadetachable
- whetherdetach()
can be called later- Throws:
NullPointerException
- if the input stream isnull
IllegalArgumentException
- ifdetach == true
butin.markSupported() == false
-
InflaterInputStream
Constructs an inflater input stream over the specified underlying input stream, with the specified options for detachability and input buffer size. The underlying stream must contain DEFLATE-compressed data with no headers or footers (e.g. must be unwrapped from the zlib or gzip container formats). Detachability allowsdetach()
to be called, and requires the specified input stream to support marking.- Parameters:
in
- the underlying input stream of raw DEFLATE-compressed datadetachable
- whetherdetach()
can be called laterinBufLen
- the size of the internal read buffer, which must be positive- Throws:
NullPointerException
- if the input stream isnull
IllegalArgumentException
- ifinBufLen < 1
IllegalArgumentException
- ifdetach == true
butin.markSupported() == false
-
InflaterInputStream
Extra constructor added for org.eclipse.mat.hprof Only safe to use copy or original once the underlying stream has been positioned to the appropriate location. Added by Eclipse MAT.- Parameters:
copy
- the original stream
-
-
Method Details
-
read
Reads the next byte of decompressed data from this stream. If data is available then a number in the range [0, 255] is returned (blocking if necessary); otherwise −1 is returned if the end of stream is reached.- Overrides:
read
in classFilterInputStream
- Returns:
- the next unsigned byte of data, or −1 for the end of stream
- Throws:
IOException
- if an I/O exception occurred in the underlying input stream, the end of stream was encountered at an unexpected position, or the compressed data has a format errorIllegalStateException
- if the stream has already been closed
-
read
Reads some bytes from the decompressed data of this stream into the specified array's subrange. This returns the number of data bytes that were stored into the array, and is in the range [−1, len]. Note that 0 can be returned even if the end of stream hasn't been reached yet.- Overrides:
read
in classFilterInputStream
- Throws:
NullPointerException
- if the array isnull
ArrayIndexOutOfBoundsException
- if the array subrange is out of boundsIOException
- if an I/O exception occurred in the underlying input stream, the end of stream was encountered at an unexpected position, or the compressed data has a format errorIllegalStateException
- if the stream has already been closed
-
mark
public void mark(int limit) Notes the current position of the output, so that later the caller can go back to this spot by calling reset. This uses the dictionary array as a cache of the last bytes returned to the caller. The dictionary is 32768 bytes in size, however when reading compressed data the inflator can generate an extra 257 bytes which are not returned to the caller but are stored in the dictionary. There is therefore a limit of 32768 - 257 = 32211 bytes that can be stored. Strictly speaking, the InputStream contract expects any value of limit to be honoured, and for implementation to add extra buffering to achieve this. Addition for Eclipse MAT.- Overrides:
mark
in classFilterInputStream
- Parameters:
limit
- the caller can read at least this many bytes before callingreset()
- See Also:
-
reset
Goes back in the output to the point wheremark(int)
was called. Addition for Eclipse MAT- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
- if it is not possible to go back to the mark point. The current position is then unchanged.- See Also:
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
- Returns:
- true
- See Also:
-
available
The number of bytes which can be read without blocking. With the underlying stream it is not clear how many bytes those will expand to so just rely on what is in the buffers. Addition for Eclipse MAT.- Overrides:
available
in classFilterInputStream
- Returns:
- the number of bytes which can be read without blocking.
- Throws:
IOException
-
skip
- Overrides:
skip
in classFilterInputStream
- Throws:
IOException
-
detach
Detaches the underlying input stream from this decompressor. This puts the underlying stream at the position of the first byte after the data that this decompressor actually consumed. Callingdetach()
invalidates this stream object but doesn't close the underlying stream.This method exists because for efficiency, the decompressor may read more bytes from the underlying stream than necessary to produce the decompressed data. If you want to continue reading the underlying stream exactly after the point the DEFLATE-compressed data ends, then it is necessary to call this detach method.
This can only be called once, and is mutually exclusive with respect to calling
close()
. It is illegal to callread()
after detaching.- Throws:
IllegalStateException
- if detach was already called or this stream has been closedIOException
- if an I/O exception occurred
-
attach
public void attach()Resume decompression. Addition for Eclipse MAT. -
toString
-
close
Closes this input stream and the underlying stream. It is illegal to callread()
ordetach()
after closing. It is idempotent to call thisclose()
method more than once.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
- if an I/O exception occurred in the underlying stream
-