Class LZMAOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

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

      Constructors 
      Constructor Description
      LZMAOutputStream​(java.io.OutputStream out, LZMA2Options options, boolean useEndMarker)
      Creates a new compressor for raw LZMA (also known as LZMA1) stream.
      LZMAOutputStream​(java.io.OutputStream out, LZMA2Options options, boolean useEndMarker, ArrayCache arrayCache)
      Creates a new compressor for raw LZMA (also known as LZMA1) stream.
      LZMAOutputStream​(java.io.OutputStream out, LZMA2Options options, long inputSize)
      Creates a new compressor for the legacy .lzma file format.
      LZMAOutputStream​(java.io.OutputStream out, LZMA2Options options, long inputSize, ArrayCache arrayCache)
      Creates a new compressor for the legacy .lzma file format.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Finishes the stream and closes the underlying OutputStream.
      void finish()
      Finishes the stream without closing the underlying OutputStream.
      void flush()
      Flushing isn't supported and will throw XZIOException.
      int getProps()
      Returns the LZMA lc/lp/pb properties encoded into a single byte.
      long getUncompressedSize()
      Gets the amount of uncompressed data written to the stream.
      void write​(byte[] buf, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LZMAOutputStream

        public LZMAOutputStream​(java.io.OutputStream out,
                                LZMA2Options options,
                                long inputSize)
                         throws java.io.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:
        java.io.IOException - may be thrown from out
      • LZMAOutputStream

        public LZMAOutputStream​(java.io.OutputStream out,
                                LZMA2Options options,
                                long inputSize,
                                ArrayCache arrayCache)
                         throws java.io.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:
        java.io.IOException - may be thrown from out
        Since:
        1.7
      • LZMAOutputStream

        public LZMAOutputStream​(java.io.OutputStream out,
                                LZMA2Options options,
                                boolean useEndMarker)
                         throws java.io.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:
        java.io.IOException - may be thrown from out
      • LZMAOutputStream

        public LZMAOutputStream​(java.io.OutputStream out,
                                LZMA2Options options,
                                boolean useEndMarker,
                                ArrayCache arrayCache)
                         throws java.io.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:
        java.io.IOException - may be thrown from out
        Since:
        1.7
    • Method Detail

      • 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 java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

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

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

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

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