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.
@param in input stream from which XZ-compressed
data is read
@throws XZFormatException
input is not in the XZ format
@throws CorruptedInputException
XZ header CRC32 doesn't match
@throws UnsupportedOptionsException
XZ header is valid but specifies options
not supported by this implementation
@throws EOFException
less than 12 bytes of input was available
from in
@throws IOException may be thrown by in
This is identical to XZInputStream(InputStream) except
that this takes also the memoryLimit argument.
@param in input stream from which XZ-compressed
data is read
@param memoryLimit memory usage limit in kibibytes (KiB)
or -1 to impose no
memory usage limit
@throws XZFormatException
input is not in the XZ format
@throws CorruptedInputException
XZ header CRC32 doesn't match
@throws UnsupportedOptionsException
XZ header is valid but specifies options
not supported by this implementation
@throws EOFException
less than 12 bytes of input was available
from in
@throws IOException may be thrown by in
Reading lots of data with read() from this input stream
may be inefficient. Wrap it in {@link java.io.BufferedInputStream}
if you need to read lots of data one byte at a time.
@return the next decompressed byte, or -1
to indicate the end of the compressed stream
@throws CorruptedInputException
@throws UnsupportedOptionsException
@throws MemoryLimitException
@throws XZIOException if the stream has been closed
@throws EOFException
compressed input is truncated or corrupt
@throws IOException may be thrown by in
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
len will immediately
buf
-1 to indicate
in
CorruptedInputException may getin.close().in.close()
Use this to decompress regular standalone .xz files. This reads from
its input stream until the end of the input or until an error occurs.
This supports decompressing concatenated .xz files.
Typical use cases
Getting an input stream to decompress a .xz file:
It's important to keep in mind that decompressor memory usage depends
on the settings used to compress the file. The worst-case memory usage
of XZInputStream is currently 1.5 GiB. Still, very few files will
require more than about 65 MiB because that's how much decompressing
a file created with the highest preset level will need, and only a few
people use settings other than the predefined presets.
It is possible to specify a memory usage limit for
XZInputStream. If decompression requires more memory thanthe specified limit, MemoryLimitException will be thrown when reading
from the stream. For example, the following sets the memory usage limit
to 100 MiB:
When uncompressed size is known beforehand
If you are decompressing complete files 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 checkingthat it returns
-1. This way the decompressor will parse thefile footers and verify the integrity checks, giving the caller more
confidence that the uncompressed data is valid. (This advice seems to
apply to
{@link java.util.zip.GZIPInputStream java.util.zip.GZIPInputStream} too.)
@see SingleXZInputStream