Getting an output stream to compress with LZMA2 using the default settings and the default integrity check type (CRC64):
FileOutputStream outfile = new FileOutputStream("foo.xz");
XZOutputStream outxz = new XZOutputStream(outfile, new LZMA2Options());
Using the preset level 8 for LZMA2 (the default
is 6) and SHA-256 instead of CRC64 for integrity checking:
XZOutputStream outxz = new XZOutputStream(outfile, new LZMA2Options(8),
XZ.CHECK_SHA256);
Using the x86 BCJ filter together with LZMA2 to compress x86 executables and printing the memory usage information before creating the XZOutputStream:
X86Options x86 = new X86Options();
LZMA2Options lzma2 = new LZMA2Options();
FilterOptions[] options = { x86, lzma2 };
System.out.println("Encoder memory usage: "
+ FilterOptions.getEncoderMemoryUsage(options)
+ " KiB");
System.out.println("Decoder memory usage: "
+ FilterOptions.getDecoderMemoryUsage(options)
+ " KiB");
XZOutputStream outxz = new XZOutputStream(outfile, options);
| Modifier and Type | Field and Description |
|---|---|
| private final ArrayCache | |
| private BlockOutputStream | |
| private final Check | |
| private IOException | |
| private FilterEncoder[] | |
| private boolean | filtersSupportFlushing
True if the current filter chain supports flushing. |
| private boolean | |
| private final IndexEncoder | |
| private OutputStream | |
| private final StreamFlags | |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions filter options to use filterOptions)Creates a new XZ compressor using one filter and CRC64 as the integrity check. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions filter options to use filterOptions, ArrayCache cache to be used for allocating large arrays arrayCache)Creates a new XZ compressor using one filter and CRC64 as the integrity check. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions filter options to use filterOptions, int type of the integrity check,
for example XZ.CHECK_CRC32 checkType)Creates a new XZ compressor using one filter and the specified integrity check type. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions filter options to use filterOptions, int type of the integrity check,
for example XZ.CHECK_CRC32 checkType, ArrayCache cache to be used for allocating large arrays arrayCache)Creates a new XZ compressor using one filter and the specified integrity check type. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions[] array of filter options to use filterOptions)Creates a new XZ compressor using 1-4 filters and CRC64 as the integrity check. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions[] array of filter options to use filterOptions, ArrayCache cache to be used for allocating large arrays arrayCache)Creates a new XZ compressor using 1-4 filters and CRC64 as the integrity check. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions[] array of filter options to use filterOptions, int type of the integrity check,
for example XZ.CHECK_CRC32 checkType)Creates a new XZ compressor using 1-4 filters and the specified integrity check type. |
| public | XZOutputStream(OutputStream
output stream to which the compressed data
will be written out, FilterOptions[] array of filter options to use filterOptions, int type of the integrity check,
for example XZ.CHECK_CRC32 checkType, ArrayCache cache to be used for allocating large arrays arrayCache)Creates a new XZ compressor using 1-4 filters and the specified integrity check type. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. |
| private void | |
| private void | |
| private void | |
| public void | |
| public void | finish()
Overrides org. |
| public void | flush()
Overrides java. Implements java. out.flush().
|
| public void | updateFilters(FilterOptions
new filter to use filterOptions)Updates the filter chain with a single filter. |
| public void | updateFilters(FilterOptions[]
new filter chain to use filterOptions)Updates the filter chain with 1-4 filters. |
| public void | write(int
the b)byte.Implements abstract java. |
| public void | write(byte[]
buffer of bytes to be written buf, int start offset in off, int bufnumber of bytes to write len)Overrides java. |
| arrayCache | back to summary |
|---|---|
| private final ArrayCache arrayCache | |
| blockEncoder | back to summary |
|---|---|
| private BlockOutputStream blockEncoder | |
| check | back to summary |
|---|---|
| private final Check check | |
| exception | back to summary |
|---|---|
| private IOException exception | |
| filters | back to summary |
|---|---|
| private FilterEncoder[] filters | |
| filtersSupportFlushing | back to summary |
|---|---|
| private boolean filtersSupportFlushing True if the current filter chain supports flushing.
If it doesn't support flushing, | |
| finished | back to summary |
|---|---|
| private boolean finished | |
| index | back to summary |
|---|---|
| private final IndexEncoder index | |
| out | back to summary |
|---|---|
| private OutputStream out | |
| streamFlags | back to summary |
|---|---|
| private final StreamFlags streamFlags | |
| tempBuf | back to summary |
|---|---|
| private final byte[] tempBuf | |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions filterOptions) throws IOException Creates a new XZ compressor using one filter and CRC64 as
the integrity check. This constructor is equivalent to passing
a single-member FilterOptions array to
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions filterOptions, ArrayCache arrayCache) throws IOException Creates a new XZ compressor using one filter and CRC64 as
the integrity check. This constructor is equivalent to passing
a single-member FilterOptions array to
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions filterOptions, int checkType) throws IOException Creates a new XZ compressor using one filter and the specified
integrity check type. This constructor is equivalent to
passing a single-member FilterOptions array to
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions filterOptions, int checkType, ArrayCache arrayCache) throws IOException Creates a new XZ compressor using one filter and the specified
integrity check type. This constructor is equivalent to
passing a single-member FilterOptions array to
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions[] filterOptions) throws IOException Creates a new XZ compressor using 1-4 filters and CRC64 as
the integrity check. This constructor is equivalent
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions[] filterOptions, ArrayCache arrayCache) throws IOException Creates a new XZ compressor using 1-4 filters and CRC64 as
the integrity check. This constructor is equivalent
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions[] filterOptions, int checkType) throws IOException Creates a new XZ compressor using 1-4 filters and the specified integrity check type.
| |
| XZOutputStream | back to summary |
|---|---|
| public XZOutputStream(OutputStream out, FilterOptions[] filterOptions, int checkType, ArrayCache arrayCache) throws IOException Creates a new XZ compressor using 1-4 filters and the specified integrity check type.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Finishes compression and closes the underlying stream.
The underlying stream
| |
| encodeStreamFlags | back to summary |
|---|---|
| private void encodeStreamFlags(byte[] buf, int off) | |
| encodeStreamFooter | back to summary |
|---|---|
| private void encodeStreamFooter() throws IOException | |
| encodeStreamHeader | back to summary |
|---|---|
| private void encodeStreamHeader() throws IOException | |
| endBlock | back to summary |
|---|---|
| public void endBlock() throws IOException Finishes the current XZ Block (but not the whole XZ Stream).
This doesn't flush the stream so it's possible that not all data will
be decompressible from the output stream when this function returns.
Call also If there is no unfinished Block open, this function will do nothing. (No empty XZ Block will be created.) This function can be useful, for example, to create random-accessible .xz files.
Starting a new XZ Block means that the encoder state is reset.
Doing this very often will increase the size of the compressed
file a lot (more than plain
| |
| finish | back to summary |
|---|---|
| public void finish() throws IOException Overrides org. Finishes compression without closing the underlying stream.
No more data can be written to this stream after finishing
(calling
Repeated calls to
After finishing, the stream may be closed normally with
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Flushes the encoder and calls Calling this function very often may increase the compressed file size a lot. The filter chain options may affect the size increase too. For example, with LZMA2 the HC4 match finder has smaller penalty with flushing than BT4.
Some filters don't support flushing. If the filter chain has
such a filter,
| |
| updateFilters | back to summary |
|---|---|
| public void updateFilters(FilterOptions filterOptions) throws XZIOException Updates the filter chain with a single filter.
This is equivalent to passing a single-member FilterOptions array
to
| |
| updateFilters | back to summary |
|---|---|
| public void updateFilters(FilterOptions[] filterOptions) throws XZIOException Updates the filter chain with 1-4 filters.
Currently this cannot be used to update e.g. LZMA2 options in the
middle of a XZ Block. Use
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Implements abstract java. Writes one byte to be compressed.
| |
| write | back to summary |
|---|---|
| public void write(byte[] buf, int off, int len) throws IOException Overrides java. Writes an array of bytes to be compressed.
The compressors tend to do internal buffering and thus the written
data won't be readable from the compressed output immediately.
Use
| |