Class TarFile
- java.lang.Object
-
- org.apache.commons.compress.archivers.tar.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.util.List<TarArchiveEntry>
getEntries()
Get all TAR Archive Entries from the TarFilejava.io.InputStream
getInputStream(TarArchiveEntry entry)
Gets the input stream for the provided Tar Archive Entry.
-
-
-
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 useencoding
- 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 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:
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 useencoding
- 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 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:
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 useencoding
- 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 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:
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 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:
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-