org.apache.commons.compress.archivers.tar

## Class TarFile

- java.lang.Object
- - org.apache.commons.compress.archivers.tar.TarFile

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class TarFile
      extends Object
      implements Closeable

  The TarFile provides random access to UNIX archives.
  Since:
    1.21

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TarFile(byte[] content)` Constructor for TarFile.
    `TarFile(byte[] content, boolean lenient)` Constructor for TarFile.
    `TarFile(byte[] content, String encoding)` Constructor for TarFile.
    `TarFile(File archive)` Constructor for TarFile.
    `TarFile(File archive, boolean lenient)` Constructor for TarFile.
    `TarFile(File archive, String encoding)` Constructor for TarFile.
    `TarFile(Path archivePath)` Constructor for TarFile.
    `TarFile(Path archivePath, boolean lenient)` Constructor for TarFile.
    `TarFile(Path archivePath, String encoding)` Constructor for TarFile.
    `TarFile(SeekableByteChannel content)` Constructor for TarFile.
    `TarFile(SeekableByteChannel archive, int blockSize, int recordSize, String encoding, boolean lenient)` Constructor for TarFile.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `List<TarArchiveEntry>` | `getEntries()` Get all TAR Archive Entries from the TarFile
    `InputStream` | `getInputStream(TarArchiveEntry entry)` Gets the input stream for the provided Tar Archive Entry.
    `protected boolean` | `isAtEOF()`
    `protected void` | `setAtEOF(boolean b)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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,
                         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(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(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,
                         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(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(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,
                         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(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(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 Detail

    - #### getEntries

          public List<TarArchiveEntry> getEntries()

      Get all TAR Archive Entries from the TarFile
      Returns:
        All entries from the tar file

    - #### isAtEOF

          protected final boolean isAtEOF()

    - #### setAtEOF

          protected final void setAtEOF(boolean b)

    - #### getInputStream

          public InputStream getInputStream(TarArchiveEntry entry)
                                     throws 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:
        `IOException` - Corrupted TAR archive. Can't read entry.

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.