Class TarFile

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

    public class TarFile
    extends java.lang.Object
    implements java.io.Closeable
    The TarFile provides random access to UNIX archives.
    Since:
    1.21
    • Constructor Summary

      Constructors 
      Constructor Description
      TarFile​(byte[] content)
      Constructor for TarFile.
      TarFile​(byte[] content, boolean lenient)
      Constructor for TarFile.
      TarFile​(byte[] content, java.lang.String encoding)
      Constructor for TarFile.
      TarFile​(java.io.File archive)
      Constructor for TarFile.
      TarFile​(java.io.File archive, boolean lenient)
      Constructor for TarFile.
      TarFile​(java.io.File archive, java.lang.String encoding)
      Constructor for TarFile.
      TarFile​(java.nio.channels.SeekableByteChannel content)
      Constructor for TarFile.
      TarFile​(java.nio.channels.SeekableByteChannel archive, int blockSize, int recordSize, java.lang.String encoding, boolean lenient)
      Constructor for TarFile.
      TarFile​(java.nio.file.Path archivePath)
      Constructor for TarFile.
      TarFile​(java.nio.file.Path archivePath, boolean lenient)
      Constructor for TarFile.
      TarFile​(java.nio.file.Path archivePath, java.lang.String encoding)
      Constructor for TarFile.
    • Constructor Detail

      • TarFile

        public TarFile​(byte[] content)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        content - the content to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(byte[] content,
                       java.lang.String encoding)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        content - the content to use
        encoding - the encoding to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(byte[] content,
                       boolean lenient)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        content - the content to use
        lenient - when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to TarArchiveEntry.UNKNOWN. When set to false such illegal fields cause an exception instead.
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.io.File archive)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archive - the file of the archive to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.io.File archive,
                       java.lang.String encoding)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archive - the file of the archive to use
        encoding - the encoding to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.io.File archive,
                       boolean lenient)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archive - the file of the archive to use
        lenient - when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to TarArchiveEntry.UNKNOWN. When set to false such illegal fields cause an exception instead.
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.nio.file.Path archivePath)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archivePath - the path of the archive to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.nio.file.Path archivePath,
                       java.lang.String encoding)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archivePath - the path of the archive to use
        encoding - the encoding to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.nio.file.Path archivePath,
                       boolean lenient)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archivePath - the path of the archive to use
        lenient - when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to TarArchiveEntry.UNKNOWN. When set to false such illegal fields cause an exception instead.
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.nio.channels.SeekableByteChannel content)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        content - the content to use
        Throws:
        java.io.IOException - when reading the tar archive fails
      • TarFile

        public TarFile​(java.nio.channels.SeekableByteChannel archive,
                       int blockSize,
                       int recordSize,
                       java.lang.String encoding,
                       boolean lenient)
                throws java.io.IOException
        Constructor for TarFile.
        Parameters:
        archive - the seekable byte channel to use
        blockSize - the blocks size to use
        recordSize - the record size to use
        encoding - the encoding to use
        lenient - when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to TarArchiveEntry.UNKNOWN. When set to false such illegal fields cause an exception instead.
        Throws:
        java.io.IOException - when reading the tar archive fails
    • Method Detail

      • getEntries

        public java.util.List<TarArchiveEntry> getEntries()
        Get all TAR Archive Entries from the TarFile
        Returns:
        All entries from the tar file
      • getInputStream

        public java.io.InputStream getInputStream​(TarArchiveEntry entry)
                                           throws java.io.IOException
        Gets the input stream for the provided Tar Archive Entry.
        Parameters:
        entry - Entry to get the input stream from
        Returns:
        Input stream of the provided entry
        Throws:
        java.io.IOException - Corrupted TAR archive. Can't read entry.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException