Class LZMAOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class LZMAOutputStream
extends FinishableOutputStream
Compresses into the legacy .lzma file format or into a raw LZMA stream.
Since:
1.6
  • Constructor Details

    • LZMAOutputStream

      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 - output stream to which the compressed data will be written
      options - LZMA compression options; the same class is used here as is for LZMA2
      inputSize - uncompressed size of the data to be compressed; use -1 when unknown
      Throws:
      IOException - may be thrown from out
    • LZMAOutputStream

      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 - output stream to which the compressed data will be written
      options - LZMA compression options; the same class is used here as is for LZMA2
      inputSize - uncompressed size of the data to be compressed; use -1 when unknown
      arrayCache - cache to be used for allocating large arrays
      Throws:
      IOException - may be thrown from out
      Since:
      1.7
    • LZMAOutputStream

      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 - output stream to which the compressed data will be written
      options - LZMA compression options; the same class is used here as is for LZMA2
      useEndMarker - if end of stream marker should be written
      Throws:
      IOException - may be thrown from out
    • LZMAOutputStream

      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 - output stream to which the compressed data will be written
      options - LZMA compression options; the same class is used here as is for LZMA2
      useEndMarker - if end of stream marker should be written
      arrayCache - cache to be used for allocating large arrays
      Throws:
      IOException - may be thrown from out
      Since:
      1.7
  • Method Details

    • getProps

      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.
    • getUncompressedSize

      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.
    • write

      public void write​(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write​(byte[] buf, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flushing isn't supported and will throw XZIOException.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • finish

      public void finish() throws IOException
      Finishes the stream without closing the underlying OutputStream.
      Overrides:
      finish in class FinishableOutputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Finishes the stream and closes the underlying OutputStream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException