java.lang.Object
org.apache.commons.compress.archivers.tar.TarFile
All Implemented Interfaces:
Closeable, AutoCloseable

public class TarFile extends Object implements Closeable
Provides random access to Unix archives.
Since:
1.21
  • Constructor Details

    • TarFile

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

      public TarFile(byte[] content, boolean lenient) throws 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:
      IOException - when reading the tar archive fails
    • TarFile

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

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

      public TarFile(File archive, boolean lenient) throws 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:
      IOException - when reading the tar archive fails
    • TarFile

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

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

      public TarFile(Path archivePath, boolean lenient) throws 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:
      IOException - when reading the tar archive fails
    • TarFile

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

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

      public TarFile(SeekableByteChannel archive, int blockSize, int recordSize, String encoding, boolean lenient) throws 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:
      IOException - when reading the tar archive fails
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getEntries

      Gets all TAR Archive Entries from the TarFile
      Returns:
      All entries from the tar file
    • getInputStream

      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:
      IOException - Corrupted TAR archive. Can't read entry.
    • isAtEOF

      protected final boolean isAtEOF()
      Tests whether or not we are at the end-of-file.
      Returns:
      whether or not we are at the end-of-file.
    • setAtEOF

      protected final void setAtEOF(boolean eof)
      Sets whether we are at end-of-file.
      Parameters:
      eof - whether we are at end-of-file.