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
    • Field Detail

      • channel

        private final java.nio.channels.SeekableByteChannel channel
      • numNonEmptyStreams

        private int numNonEmptyStreams
      • crc32

        private final java.util.zip.CRC32 crc32
      • compressedCrc32

        private final java.util.zip.CRC32 compressedCrc32
      • fileBytesWritten

        private long fileBytesWritten
      • finished

        private boolean finished
      • additionalSizes

        private final java.util.Map<SevenZArchiveEntry,​long[]> additionalSizes
    • 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
      • 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
      • 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.
      • getCurrentOutputStream

        private java.io.OutputStream getCurrentOutputStream()
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setupFileOutputStream

        private CountingOutputStream setupFileOutputStream()
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHeader

        private void writeHeader​(java.io.DataOutput header)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStreamsInfo

        private void writeStreamsInfo​(java.io.DataOutput header)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writePackInfo

        private void writePackInfo​(java.io.DataOutput header)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeUnpackInfo

        private void writeUnpackInfo​(java.io.DataOutput header)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFolder

        private void writeFolder​(java.io.DataOutput header,
                                 SevenZArchiveEntry entry)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSingleCodec

        private void writeSingleCodec​(SevenZMethodConfiguration m,
                                      java.io.OutputStream bos)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSubStreamsInfo

        private void writeSubStreamsInfo​(java.io.DataOutput header)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFilesInfo

        private void writeFilesInfo​(java.io.DataOutput header)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileEmptyStreams

        private void writeFileEmptyStreams​(java.io.DataOutput header)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileEmptyFiles

        private void writeFileEmptyFiles​(java.io.DataOutput header)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileAntiItems

        private void writeFileAntiItems​(java.io.DataOutput header)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileNames

        private void writeFileNames​(java.io.DataOutput header)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileCTimes

        private void writeFileCTimes​(java.io.DataOutput header)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileATimes

        private void writeFileATimes​(java.io.DataOutput header)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileMTimes

        private void writeFileMTimes​(java.io.DataOutput header)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFileWindowsAttributes

        private void writeFileWindowsAttributes​(java.io.DataOutput header)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • writeUint64

        private void writeUint64​(java.io.DataOutput header,
                                 long value)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBits

        private void writeBits​(java.io.DataOutput header,
                               java.util.BitSet bits,
                               int length)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • reverse

        private static <T> java.lang.Iterable<T> reverse​(java.lang.Iterable<T> i)