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.
Getting an input stream to decompress a .xz file:
InputStream infile = new FileInputStream("foo.xz");
XZInputStream inxz = new XZInputStream(infile);
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 than
the specified limit, MemoryLimitException will be thrown when reading
from the stream. For example, the following sets the memory usage limit
to 100 MiB:
InputStream infile = new FileInputStream("foo.xz");
XZInputStream inxz = new XZInputStream(infile, 100 * 1024);
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 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. (This advice seems to
apply to
java. too.)
SingleXZInputStream
| Modifier and Type | Field and Description |
|---|---|
| private final ArrayCache | |
| private boolean | |
| private IOException | |
| private InputStream | |
| private final int | |
| private final byte[] | |
| private final boolean | |
| private SingleXZInputStream |
| Access | Constructor and Description |
|---|---|
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in)Creates a new XZ decompressor without a memory usage limit. |
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in, ArrayCache cache to be used for allocating large arrays arrayCache)Creates a new XZ decompressor without a memory usage limit. |
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in, int memory usage limit in kibibytes (KiB)
or memoryLimit)-1 to impose no
memory usage limitCreates a new XZ decompressor with an optional memory usage limit. |
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in, int memory usage limit in kibibytes (KiB)
or memoryLimit, ArrayCache -1 to impose no
memory usage limitcache to be used for allocating large arrays arrayCache)Creates a new XZ decompressor with an optional memory usage limit. |
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in, int memory usage limit in kibibytes (KiB)
or memoryLimit, boolean -1 to impose no
memory usage limitif verifyCheck)true, the integrity checks
will be verified; this should almost never
be set to falseCreates a new XZ decompressor with an optional memory usage limit and ability to disable verification of integrity checks. |
| public | XZInputStream(InputStream
input stream from which XZ-compressed
data is read in, int memory usage limit in kibibytes (KiB)
or memoryLimit, boolean -1 to impose no
memory usage limitif verifyCheck, ArrayCache true, the integrity checks
will be verified; this should almost never
be set to falsecache to be used for allocating large arrays arrayCache)Creates a new XZ decompressor with an optional memory usage limit and ability to disable verification of integrity checks. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: the number of uncompressed bytes that can be read without blockingOverrides java. |
| public void | close()
Overrides java. Implements java. in.close().
|
| public void | |
| private void | |
| public int | Returns: the next decompressed byte, or-1
to indicate the end of the compressed streamImplements abstract java. |
| public int | Returns: number of bytes read, or-1 to indicate
the end of the compressed streamtarget buffer for uncompressed data buf, int start offset in off, int bufmaximum number of uncompressed bytes to read len)Overrides java. |
| arrayCache | back to summary |
|---|---|
| private final ArrayCache arrayCache | |
| endReached | back to summary |
|---|---|
| private boolean endReached | |
| exception | back to summary |
|---|---|
| private IOException exception | |
| in | back to summary |
|---|---|
| private InputStream in | |
| memoryLimit | back to summary |
|---|---|
| private final int memoryLimit | |
| tempBuf | back to summary |
|---|---|
| private final byte[] tempBuf | |
| verifyCheck | back to summary |
|---|---|
| private final boolean verifyCheck | |
| xzIn | back to summary |
|---|---|
| private SingleXZInputStream xzIn | |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in) throws IOException Creates a new XZ decompressor without a memory usage limit.
This constructor reads and parses the XZ Stream Header (12 bytes)
from
| |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in, ArrayCache arrayCache) throws IOException Creates a new XZ decompressor without a memory usage limit.
This is identical to
| |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in, int memoryLimit) throws IOException Creates a new XZ decompressor with an optional memory usage limit.
This is identical to
| |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in, int memoryLimit, ArrayCache arrayCache) throws IOException Creates a new XZ decompressor with an optional memory usage limit.
This is identical to
| |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in, int memoryLimit, boolean verifyCheck) throws IOException Creates a new XZ decompressor with an optional memory usage limit and ability to disable verification of integrity checks.
This is identical to Note that integrity check verification should almost never be disabled. Possible reasons to disable integrity check verification:
| |
| XZInputStream | back to summary |
|---|---|
| public XZInputStream(InputStream in, int memoryLimit, boolean verifyCheck, ArrayCache arrayCache) throws IOException Creates a new XZ decompressor with an optional memory usage limit and ability to disable verification of integrity checks.
This is identical to
| |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Returns the number of uncompressed bytes that can be read
without blocking. The value is returned with an assumption
that the compressed input data will be valid. If the compressed
data is corrupt,
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes the stream and calls
This is equivalent to
| |
| close | back to summary |
|---|---|
| public void close(boolean closeInput) throws IOException Closes the stream and optionally calls
If you don't want to close the underlying
Note that if you successfully reach the end of the stream
(
| |
| prepareNextStream | back to summary |
|---|---|
| private void prepareNextStream() throws IOException | |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Decompresses the next byte from this input stream.
Reading lots of data with
| |
| read | back to summary |
|---|---|
| public int read(byte[] buf, int off, int len) throws IOException Overrides java. Decompresses into an array of bytes.
If
| |