Top Description Fields Constructors Methods
org.tukaani.xz

public Class LZMAOutputStream

extends FinishableOutputStream
Class Inheritance
Imports
java.io.OutputStream, .IOException, org.tukaani.xz.lz.LZEncoder, org.tukaani.xz.rangecoder.RangeEncoderToStream, org.tukaani.xz.lzma.LZMAEncoder

Compresses into the legacy .lzma file format or into a raw LZMA stream.
Since
1.6

Field Summary

Modifier and TypeField and Description
private final ArrayCache
private long
private IOException
private final long
private boolean
private LZEncoder
private LZMAEncoder
private OutputStream
private final int
private final RangeEncoderToStream
private final byte[]
private final boolean

Constructor Summary

AccessConstructor and Description
private
LZMAOutputStream(OutputStream out, LZMA2Options options, boolean useHeader, boolean useEndMarker, long expectedUncompressedSize, ArrayCache arrayCache)

public
LZMAOutputStream(OutputStream
output stream to which the compressed data will be written
out
,
LZMA2Options
LZMA compression options; the same class is used here as is for LZMA2
options
,
long
uncompressed size of the data to be compressed; use -1 when unknown
inputSize
)

Creates a new compressor for the legacy .lzma file format.

public
LZMAOutputStream(OutputStream
output stream to which the compressed data will be written
out
,
LZMA2Options
LZMA compression options; the same class is used here as is for LZMA2
options
,
long
uncompressed size of the data to be compressed; use -1 when unknown
inputSize
,
ArrayCache
cache to be used for allocating large arrays
arrayCache
)

Creates a new compressor for the legacy .lzma file format.

public
LZMAOutputStream(OutputStream
output stream to which the compressed data will be written
out
,
LZMA2Options
LZMA compression options; the same class is used here as is for LZMA2
options
,
boolean
if end of stream marker should be written
useEndMarker
)

Creates a new compressor for raw LZMA (also known as LZMA1) stream.

public
LZMAOutputStream(OutputStream
output stream to which the compressed data will be written
out
,
LZMA2Options
LZMA compression options; the same class is used here as is for LZMA2
options
,
boolean
if end of stream marker should be written
useEndMarker
,
ArrayCache
cache to be used for allocating large arrays
arrayCache
)

Creates a new compressor for raw LZMA (also known as LZMA1) stream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Finishes the stream and closes the underlying OutputStream.
public void
finish()

Overrides org.tukaani.xz.FinishableOutputStream.finish.

Finishes the stream without closing the underlying OutputStream.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushing isn't supported and will throw XZIOException.
public int
getProps()

Returns the LZMA lc/lp/pb properties encoded into a single byte.

public long
getUncompressedSize()

Gets the amount of uncompressed data written to the stream.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
buf
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Field Detail

arrayCacheback to summary
private final ArrayCache arrayCache
currentUncompressedSizeback to summary
private long currentUncompressedSize
exceptionback to summary
private IOException exception
expectedUncompressedSizeback to summary
private final long expectedUncompressedSize
finishedback to summary
private boolean finished
lzback to summary
private LZEncoder lz
lzmaback to summary
private LZMAEncoder lzma
outback to summary
private OutputStream out
propsback to summary
private final int props
rcback to summary
private final RangeEncoderToStream rc
tempBufback to summary
private final byte[] tempBuf
useEndMarkerback to summary
private final boolean useEndMarker

Constructor Detail

LZMAOutputStreamback to summary
private LZMAOutputStream(OutputStream out, LZMA2Options options, boolean useHeader, boolean useEndMarker, long expectedUncompressedSize, ArrayCache arrayCache) throws IOException
LZMAOutputStreamback to summary
public LZMAOutputStream(OutputStream out, LZMA2Options options, long inputSize) throws IOException

Creates a new compressor for the legacy .lzma file format.

If the uncompressed size of the input data is known, it will be stored in the .lzma header and no end of stream marker will be used. Otherwise the header will indicate unknown uncompressed size and the end of stream marker will be used.

Note that a preset dictionary cannot be used in .lzma files but it can be used for raw LZMA streams.

Parameters
out:OutputStream

output stream to which the compressed data will be written

options:LZMA2Options

LZMA compression options; the same class is used here as is for LZMA2

inputSize:long

uncompressed size of the data to be compressed; use -1 when unknown

Exceptions
IOException:
may be thrown from out
LZMAOutputStreamback to summary
public LZMAOutputStream(OutputStream out, LZMA2Options options, long inputSize, ArrayCache arrayCache) throws IOException

Creates a new compressor for the legacy .lzma file format.

This is identical to LZMAOutputStream(OutputStream, LZMA2Options, long) except that this also takes the arrayCache argument.

Parameters
out:OutputStream

output stream to which the compressed data will be written

options:LZMA2Options

LZMA compression options; the same class is used here as is for LZMA2

inputSize:long

uncompressed size of the data to be compressed; use -1 when unknown

arrayCache:ArrayCache

cache to be used for allocating large arrays

Exceptions
IOException:
may be thrown from out
Since
1.7
LZMAOutputStreamback to summary
public LZMAOutputStream(OutputStream out, LZMA2Options options, boolean useEndMarker) throws IOException

Creates a new compressor for raw LZMA (also known as LZMA1) stream.

Raw LZMA streams can be encoded with or without end of stream marker. When decompressing the stream, one must know if the end marker was used and tell it to the decompressor. If the end marker wasn't used, the decompressor will also need to know the uncompressed size.

Parameters
out:OutputStream

output stream to which the compressed data will be written

options:LZMA2Options

LZMA compression options; the same class is used here as is for LZMA2

useEndMarker:boolean

if end of stream marker should be written

Exceptions
IOException:
may be thrown from out
LZMAOutputStreamback to summary
public LZMAOutputStream(OutputStream out, LZMA2Options options, boolean useEndMarker, ArrayCache arrayCache) throws IOException

Creates a new compressor for raw LZMA (also known as LZMA1) stream.

This is identical to LZMAOutputStream(OutputStream, LZMA2Options, boolean) except that this also takes the arrayCache argument.

Parameters
out:OutputStream

output stream to which the compressed data will be written

options:LZMA2Options

LZMA compression options; the same class is used here as is for LZMA2

useEndMarker:boolean

if end of stream marker should be written

arrayCache:ArrayCache

cache to be used for allocating large arrays

Exceptions
IOException:
may be thrown from out
Since
1.7

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Finishes the stream and closes the underlying OutputStream.

Exceptions
IOException:

Doc from java.io.OutputStream.close.

if an I/O error occurs.

finishback to summary
public void finish() throws IOException

Overrides org.tukaani.xz.FinishableOutputStream.finish.

Finishes the stream without closing the underlying OutputStream.

flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushing isn't supported and will throw XZIOException.

Exceptions
IOException:

Doc from java.io.OutputStream.flush.

if an I/O error occurs.

getPropsback to summary
public int getProps()

Returns the LZMA lc/lp/pb properties encoded into a single byte. This might be useful when handling file formats other than .lzma that use the same encoding for the LZMA properties as .lzma does.

getUncompressedSizeback to summary
public long getUncompressedSize()

Gets the amount of uncompressed data written to the stream. This is useful when creating raw LZMA streams without the end of stream marker.

writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] buf, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
buf:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.