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 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(SeekableByteChannel content)
Constructor for TarFile.TarFile(SeekableByteChannel archive, int blockSize, int recordSize, String encoding, boolean lenient)
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
List<TarArchiveEntry>
getEntries()
Get all TAR Archive Entries from the TarFileInputStream
getInputStream(TarArchiveEntry entry)
Gets the input stream for the provided Tar Archive Entry.
-
-
-
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 useencoding
- 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 uselenient
- when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set toTarArchiveEntry.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 useencoding
- 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 uselenient
- when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set toTarArchiveEntry.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 useencoding
- 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 uselenient
- when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set toTarArchiveEntry.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 useblockSize
- the blocks size to userecordSize
- the record size to useencoding
- the encoding to uselenient
- when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set toTarArchiveEntry.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
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-