Class ArchiveOutputStream<E extends ArchiveEntry>

    • Constructor Summary

      Constructors 
      Constructor Description
      ArchiveOutputStream()
      Constructs a new instance without a backing OutputStream.
      ArchiveOutputStream​(java.io.OutputStream out)
      Constructs a new instance with the given backing OutputStream.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean canWriteEntryData​(ArchiveEntry archiveEntry)
      Tests whether this stream is able to write the given entry.
      abstract void closeArchiveEntry()
      Closes the archive entry, writing any trailer information that may be required.
      abstract E createArchiveEntry​(java.io.File inputFile, java.lang.String entryName)
      Creates an archive entry using the inputFile and entryName provided.
      E createArchiveEntry​(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options)
      Creates an archive entry using the inputPath and entryName provided.
      long getBytesWritten()
      Gets the current number of bytes written to this stream.
      int getCount()
      Deprecated.
      this method may yield wrong results for large archives, use #getBytesWritten instead
      abstract void putArchiveEntry​(E entry)
      Writes the headers for an archive entry to the output stream.
      void write​(int b)
      Writes a byte to the current archive entry.
      • Methods inherited from class java.io.FilterOutputStream

        flush, write, write
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • ArchiveOutputStream

        public ArchiveOutputStream()
        Constructs a new instance without a backing OutputStream.

        You must initialize this.out after construction.

      • ArchiveOutputStream

        public ArchiveOutputStream​(java.io.OutputStream out)
        Constructs a new instance with the given backing OutputStream.
        Parameters:
        out - the underlying output stream to be assigned to the field this.out for later use, or null if this instance is to be created without an underlying stream.
        Since:
        1.27.0.
    • Method Detail

      • canWriteEntryData

        public boolean canWriteEntryData​(ArchiveEntry archiveEntry)
        Tests whether this stream is able to write the given entry.

        Some archive formats support variants or details that are not supported (yet).

        Parameters:
        archiveEntry - the entry to test
        Returns:
        This implementation always returns true.
        Since:
        1.1
      • closeArchiveEntry

        public abstract void closeArchiveEntry()
                                        throws java.io.IOException
        Closes the archive entry, writing any trailer information that may be required.
        Throws:
        java.io.IOException - if an I/O error occurs
      • createArchiveEntry

        public abstract E createArchiveEntry​(java.io.File inputFile,
                                             java.lang.String entryName)
                                      throws java.io.IOException
        Creates an archive entry using the inputFile and entryName provided.
        Parameters:
        inputFile - the file to create the entry from
        entryName - name to use for the entry
        Returns:
        the ArchiveEntry set up with details from the file
        Throws:
        java.io.IOException - if an I/O error occurs
      • createArchiveEntry

        public E createArchiveEntry​(java.nio.file.Path inputPath,
                                    java.lang.String entryName,
                                    java.nio.file.LinkOption... options)
                             throws java.io.IOException
        Creates an archive entry using the inputPath and entryName provided.

        The default implementation calls simply delegates as:

         return createArchiveEntry(inputFile.toFile(), entryName);
         

        Subclasses should override this method.

        Parameters:
        inputPath - the file to create the entry from
        entryName - name to use for the entry
        options - options indicating how symbolic links are handled.
        Returns:
        the ArchiveEntry set up with details from the file
        Throws:
        java.io.IOException - if an I/O error occurs
        Since:
        1.21
      • getBytesWritten

        public long getBytesWritten()
        Gets the current number of bytes written to this stream.
        Returns:
        the number of written bytes
        Since:
        1.1
      • getCount

        @Deprecated
        public int getCount()
        Deprecated.
        this method may yield wrong results for large archives, use #getBytesWritten instead
        Gets the current number of bytes written to this stream.
        Returns:
        the number of written bytes
      • putArchiveEntry

        public abstract void putArchiveEntry​(E entry)
                                      throws java.io.IOException
        Writes the headers for an archive entry to the output stream. The caller must then write the content to the stream and call closeArchiveEntry() to complete the process.
        Parameters:
        entry - describes the entry
        Throws:
        java.io.IOException - if an I/O error occurs
      • write

        public void write​(int b)
                   throws java.io.IOException
        Writes a byte to the current archive entry.

        This method simply calls write( byte[], 0, 1 ).

        MUST be overridden if the FilterOutputStream.write(byte[], int, int) method is not overridden; may be overridden otherwise.

        Overrides:
        write in class java.io.FilterOutputStream
        Parameters:
        b - The byte to be written.
        Throws:
        java.io.IOException - on error