public class SingleXZInputStream extends InputStream
Unless you know what you are doing, don't use this class to decompress
standalone .xz files. For that purpose, use XZInputStream
.
If you are decompressing complete XZ streams and your application knows
exactly how much uncompressed data there should be, it is good to try
reading one more byte by calling read()
and checking
that it returns -1
. This way the decompressor will parse the
file footers and verify the integrity checks, giving the caller more
confidence that the uncompressed data is valid.
XZInputStream
Constructor and Description |
---|
SingleXZInputStream(InputStream in)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in without a memory usage limit. |
SingleXZInputStream(InputStream in,
ArrayCache arrayCache)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in without a memory usage limit. |
SingleXZInputStream(InputStream in,
int memoryLimit)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in with an optional memory usage limit. |
SingleXZInputStream(InputStream in,
int memoryLimit,
ArrayCache arrayCache)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in with an optional memory usage limit. |
SingleXZInputStream(InputStream in,
int memoryLimit,
boolean verifyCheck)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in with an optional memory usage limit
and ability to disable verification of integrity checks. |
SingleXZInputStream(InputStream in,
int memoryLimit,
boolean verifyCheck,
ArrayCache arrayCache)
Creates a new XZ decompressor that decompresses exactly one
XZ Stream from
in with an optional memory usage limit
and ability to disable verification of integrity checks. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of uncompressed bytes that can be read
without blocking.
|
void |
close()
Closes the stream and calls
in.close() . |
void |
close(boolean closeInput)
Closes the stream and optionally calls
in.close() . |
String |
getCheckName()
Gets the name of the integrity check used in this XZ Stream.
|
int |
getCheckType()
Gets the ID of the integrity check used in this XZ Stream.
|
int |
read()
Decompresses the next byte from this input stream.
|
int |
read(byte[] buf,
int off,
int len)
Decompresses into an array of bytes.
|
mark, markSupported, read, reset, skip
public SingleXZInputStream(InputStream in) throws IOException
in
without a memory usage limit.
This constructor reads and parses the XZ Stream Header (12 bytes)
from in
. The header of the first Block is not read
until read
is called.
in
- input stream from which XZ-compressed
data is readXZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public SingleXZInputStream(InputStream in, ArrayCache arrayCache) throws IOException
in
without a memory usage limit.
This is identical to SingleXZInputStream(InputStream)
except that this also takes the arrayCache
argument.
in
- input stream from which XZ-compressed
data is readarrayCache
- cache to be used for allocating large arraysXZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public SingleXZInputStream(InputStream in, int memoryLimit) throws IOException
in
with an optional memory usage limit.
This is identical to SingleXZInputStream(InputStream)
except that this also takes the memoryLimit
argument.
in
- input stream from which XZ-compressed
data is readmemoryLimit
- memory usage limit in kibibytes (KiB)
or -1
to impose no
memory usage limitXZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public SingleXZInputStream(InputStream in, int memoryLimit, ArrayCache arrayCache) throws IOException
in
with an optional memory usage limit.
This is identical to SingleXZInputStream(InputStream)
except that this also takes the memoryLimit
and
arrayCache
arguments.
in
- input stream from which XZ-compressed
data is readmemoryLimit
- memory usage limit in kibibytes (KiB)
or -1
to impose no
memory usage limitarrayCache
- cache to be used for allocating large arraysXZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public SingleXZInputStream(InputStream in, int memoryLimit, boolean verifyCheck) throws IOException
in
with an optional memory usage limit
and ability to disable verification of integrity checks.
This is identical to SingleXZInputStream(InputStream,int)
except that this also takes the verifyCheck
argument.
Note that integrity check verification should almost never be disabled. Possible reasons to disable integrity check verification:
verifyCheck
only affects the integrity check of
the actual compressed data. The CRC32 fields in the headers
are always verified.
in
- input stream from which XZ-compressed
data is readmemoryLimit
- memory usage limit in kibibytes (KiB)
or -1
to impose no
memory usage limitverifyCheck
- if true
, the integrity checks
will be verified; this should almost never
be set to false
XZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public SingleXZInputStream(InputStream in, int memoryLimit, boolean verifyCheck, ArrayCache arrayCache) throws IOException
in
with an optional memory usage limit
and ability to disable verification of integrity checks.
This is identical to
SingleXZInputStream(InputStream,int,boolean)
except that this also takes the arrayCache
argument.
in
- input stream from which XZ-compressed
data is readmemoryLimit
- memory usage limit in kibibytes (KiB)
or -1
to impose no
memory usage limitverifyCheck
- if true
, the integrity checks
will be verified; this should almost never
be set to false
arrayCache
- cache to be used for allocating large arraysXZFormatException
- input is not in the XZ formatCorruptedInputException
- XZ header CRC32 doesn't matchUnsupportedOptionsException
- XZ header is valid but specifies options
not supported by this implementationEOFException
- less than 12 bytes of input was available
from in
IOException
- may be thrown by in
public int getCheckType()
public String getCheckName()
public int read() throws IOException
Reading lots of data with read()
from this input stream
may be inefficient. Wrap it in BufferedInputStream
if you need to read lots of data one byte at a time.
read
in class InputStream
-1
to indicate the end of the compressed streamCorruptedInputException
UnsupportedOptionsException
MemoryLimitException
XZIOException
- if the stream has been closedEOFException
- compressed input is truncated or corruptIOException
- may be thrown by in
public int read(byte[] buf, int off, int len) throws IOException
If len
is zero, no bytes are read and 0
is returned. Otherwise this will try to decompress len
bytes of uncompressed data. Less than len
bytes may
be read only in the following situations:
len
bytes have already been successfully decompressed.
The next call with non-zero len
will immediately
throw the pending exception.read
in class InputStream
buf
- target buffer for uncompressed dataoff
- start offset in buf
len
- maximum number of uncompressed bytes to read-1
to indicate
the end of the compressed streamCorruptedInputException
UnsupportedOptionsException
MemoryLimitException
XZIOException
- if the stream has been closedEOFException
- compressed input is truncated or corruptIOException
- may be thrown by in
public int available() throws IOException
CorruptedInputException
may get
thrown before the number of bytes claimed to be available have
been read from this input stream.available
in class InputStream
IOException
public void close() throws IOException
in.close()
.
If the stream was already closed, this does nothing.
This is equivalent to close(true)
.
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
- if thrown by in.close()
public void close(boolean closeInput) throws IOException
in.close()
.
If the stream was already closed, this does nothing.
If close(false)
has been called, a further
call of close(true)
does nothing (it doesn't call
in.close()
).
If you don't want to close the underlying InputStream
,
there is usually no need to worry about closing this stream either;
it's fine to do nothing and let the garbage collector handle it.
However, if you are using ArrayCache
, close(false)
can be useful to put the allocated arrays back to the cache without
closing the underlying InputStream
.
Note that if you successfully reach the end of the stream
(read
returns -1
), the arrays are
automatically put back to the cache by that read
call. In
this situation close(false)
is redundant (but harmless).
IOException
- if thrown by in.close()