Package io.nayuki.deflate
Class InflaterInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- io.nayuki.deflate.InflaterInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class InflaterInputStream extends java.io.FilterInputStream
Decompresses a DEFLATE data stream (raw format without zlib or gzip headers or footers) into a byte stream.
-
-
Constructor Summary
Constructors Constructor Description InflaterInputStream(InflaterInputStream copy)
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.InflaterInputStream(java.io.InputStream in, boolean detachable)
Constructs an inflater input stream over the specified underlying input stream, and with the specified option for detachability.InflaterInputStream(java.io.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attach()
Resume decompression.int
available()
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
markSupported()
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)
java.lang.String
toString()
-
-
-
Constructor Detail
-
InflaterInputStream
public InflaterInputStream(java.io.InputStream in, boolean detachable)
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:
java.lang.NullPointerException
- if the input stream isnull
java.lang.IllegalArgumentException
- ifdetach == true
butin.markSupported() == false
-
InflaterInputStream
public InflaterInputStream(java.io.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. 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:
java.lang.NullPointerException
- if the input stream isnull
java.lang.IllegalArgumentException
- ifinBufLen < 1
java.lang.IllegalArgumentException
- ifdetach == true
butin.markSupported() == false
-
InflaterInputStream
public InflaterInputStream(InflaterInputStream copy)
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 Detail
-
read
public int read() throws java.io.IOException
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 classjava.io.FilterInputStream
- Returns:
- the next unsigned byte of data, or −1 for the end of stream
- Throws:
java.io.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 errorjava.lang.IllegalStateException
- if the stream has already been closed
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
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 classjava.io.FilterInputStream
- Throws:
java.lang.NullPointerException
- if the array isnull
java.lang.ArrayIndexOutOfBoundsException
- if the array subrange is out of boundsjava.io.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 errorjava.lang.IllegalStateException
- 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.
-
reset
public void reset() throws java.io.IOException
Goes back in the output to the point wheremark(int)
was called. Addition for Eclipse MAT- Overrides:
reset
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- if it is not possible to go back to the mark point. The current position is then unchanged.- See Also:
mark(int)
-
markSupported
public boolean markSupported()
-
available
public int available() throws java.io.IOException
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 classjava.io.FilterInputStream
- Returns:
- the number of bytes which can be read without blocking.
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
detach
public void detach() throws java.io.IOException
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:
java.lang.IllegalStateException
- if detach was already called or this stream has been closedjava.io.IOException
- if an I/O exception occurred
-
attach
public void attach()
Resume decompression. Addition for Eclipse MAT.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
close
public void close() throws java.io.IOException
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- if an I/O exception occurred in the underlying stream
-
-