Class SevenZOutputFile

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

    public class SevenZOutputFile
    extends java.lang.Object
    implements java.io.Closeable
    Writes a 7z file.
    Since:
    1.6
    • Constructor Summary

      Constructors 
      Constructor Description
      SevenZOutputFile​(java.io.File fileName)
      Opens file to write a 7z archive to.
      SevenZOutputFile​(java.nio.channels.SeekableByteChannel channel)
      Prepares channel to write a 7z archive to.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the archive, calling finish() if necessary.
      void closeArchiveEntry()
      Closes the archive entry.
      SevenZArchiveEntry createArchiveEntry​(java.io.File inputFile, java.lang.String entryName)
      Create an archive entry using the inputFile and entryName provided.
      SevenZArchiveEntry createArchiveEntry​(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options)
      Create an archive entry using the inputPath and entryName provided.
      void finish()
      Finishes the addition of entries to this archive, without closing it.
      void putArchiveEntry​(ArchiveEntry archiveEntry)
      Records an archive entry to add.
      void setContentCompression​(SevenZMethod method)
      Sets the default compression method to use for entry contents - the default is LZMA2.
      void setContentMethods​(java.lang.Iterable<? extends SevenZMethodConfiguration> methods)
      Sets the default (compression) methods to use for entry contents - the default is LZMA2.
      void write​(byte[] b)
      Writes a byte array to the current archive entry.
      void write​(byte[] b, int off, int len)
      Writes part of a byte array to the current archive entry.
      void write​(int b)
      Writes a byte to the current archive entry.
      void write​(java.io.InputStream inputStream)
      Writes all of the given input stream to the current archive entry.
      void write​(java.nio.file.Path path, java.nio.file.OpenOption... options)
      Writes all of the given input stream to the current archive entry.
      • Methods inherited from class java.lang.Object

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

      • SevenZOutputFile

        public SevenZOutputFile​(java.io.File fileName)
                         throws java.io.IOException
        Opens file to write a 7z archive to.
        Parameters:
        fileName - the file to write to
        Throws:
        java.io.IOException - if opening the file fails
      • SevenZOutputFile

        public SevenZOutputFile​(java.nio.channels.SeekableByteChannel channel)
                         throws java.io.IOException
        Prepares channel to write a 7z archive to.

        SeekableInMemoryByteChannel allows you to write to an in-memory archive.

        Parameters:
        channel - the channel to write to
        Throws:
        java.io.IOException - if the channel cannot be positioned properly
        Since:
        1.13
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes the archive, calling finish() if necessary.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - on error
      • createArchiveEntry

        public SevenZArchiveEntry createArchiveEntry​(java.io.File inputFile,
                                                     java.lang.String entryName)
                                              throws java.io.IOException
        Create an archive entry using the inputFile and entryName provided.
        Parameters:
        inputFile - file to create an entry from
        entryName - the name to use
        Returns:
        the ArchiveEntry set up with details from the file
        Throws:
        java.io.IOException - on error
      • createArchiveEntry

        public SevenZArchiveEntry createArchiveEntry​(java.nio.file.Path inputPath,
                                                     java.lang.String entryName,
                                                     java.nio.file.LinkOption... options)
                                              throws java.io.IOException
        Create an archive entry using the inputPath and entryName provided.
        Parameters:
        inputPath - path to create an entry from
        entryName - the name to use
        options - options indicating how symbolic links are handled.
        Returns:
        the ArchiveEntry set up with details from the file
        Throws:
        java.io.IOException - on error
        Since:
        1.21
      • putArchiveEntry

        public void putArchiveEntry​(ArchiveEntry archiveEntry)
                             throws java.io.IOException
        Records an archive entry to add. The caller must then write the content to the archive and call closeArchiveEntry() to complete the process.
        Parameters:
        archiveEntry - describes the entry
        Throws:
        java.io.IOException - on error
      • closeArchiveEntry

        public void closeArchiveEntry()
                               throws java.io.IOException
        Closes the archive entry.
        Throws:
        java.io.IOException - on error
      • write

        public void write​(int b)
                   throws java.io.IOException
        Writes a byte to the current archive entry.
        Parameters:
        b - The byte to be written.
        Throws:
        java.io.IOException - on error
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Writes a byte array to the current archive entry.
        Parameters:
        b - The byte array to be written.
        Throws:
        java.io.IOException - on error
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Writes part of a byte array to the current archive entry.
        Parameters:
        b - The byte array to be written.
        off - offset into the array to start writing from
        len - number of bytes to write
        Throws:
        java.io.IOException - on error
      • write

        public void write​(java.io.InputStream inputStream)
                   throws java.io.IOException
        Writes all of the given input stream to the current archive entry.
        Parameters:
        inputStream - the data source.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.21
      • write

        public void write​(java.nio.file.Path path,
                          java.nio.file.OpenOption... options)
                   throws java.io.IOException
        Writes all of the given input stream to the current archive entry.
        Parameters:
        path - the data source.
        options - options specifying how the file is opened.
        Throws:
        java.io.IOException - if an I/O error occurs.
        Since:
        1.21
      • finish

        public void finish()
                    throws java.io.IOException
        Finishes the addition of entries to this archive, without closing it.
        Throws:
        java.io.IOException - if archive is already closed.