public class TarFile extends java.lang.Object implements ArchiveFile
Implementation of ArchiveFile
for tar files.
Compared to
ZipFile
, this one should be used with some care, due to the
nature of a tar file: While a zip file contains a catalog, a tar
file does not. In other words, the only way to read a tar file in
a performant manner is by iterating over it from the beginning to
the end. If you try to open another entry than the "next" entry,
then you force to skip entries, until the requested entry is found.
This may require to reread the entire file!
In other words, the recommended use of this class is to use
getEntries()
and invoke getInputStream(TarArchiveEntry)
only for the current entry. Basically, this is to handle it like
TarArchiveInputStream
.
The advantage of this class is that you may write code for the
ArchiveFile
, which is valid for both tar files and zip files.
Modifier and Type | Field and Description |
---|---|
private org.apache.commons.compress.archivers.tar.TarArchiveEntry |
currentEntry |
private java.io.File |
file |
private org.apache.commons.compress.archivers.tar.TarArchiveInputStream |
inputStream |
Constructor and Description |
---|
TarFile(java.io.File file)
Creates a new instance with the given file.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
private boolean |
findEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry,
org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry) |
java.util.Enumeration<org.apache.commons.compress.archivers.ArchiveEntry> |
getEntries()
Implementation of
ArchiveFile.getEntries() . |
java.io.InputStream |
getInputStream(org.apache.commons.compress.archivers.ArchiveEntry entry)
Returns an
InputStream with the given entries contents. |
protected java.io.InputStream |
getInputStream(java.io.File file) |
java.io.InputStream |
getInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry)
Returns an
InputStream with the given entries
contents. |
private java.io.InputStream |
getInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry,
org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry) |
private void |
open() |
private final java.io.File file
private org.apache.commons.compress.archivers.tar.TarArchiveInputStream inputStream
private org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry
public TarFile(java.io.File file)
public java.util.Enumeration<org.apache.commons.compress.archivers.ArchiveEntry> getEntries() throws java.io.IOException
ArchiveFile.getEntries()
. Note, that there is
an interaction between this method and getInputStream(TarArchiveEntry)
,
or getInputStream(org.apache.commons.compress.archivers.ArchiveEntry)
:
If an input stream is opened for any other entry than the enumerations
current entry, then entries may be skipped.getEntries
in interface ArchiveFile
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
public java.io.InputStream getInputStream(org.apache.commons.compress.archivers.ArchiveEntry entry) throws java.io.IOException
ArchiveFile
InputStream
with the given entries contents.
org.apache.commons.compress.archivers.ArchiveEntrygetInputStream
in interface ArchiveFile
java.io.IOException
public java.io.InputStream getInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry) throws java.io.IOException
InputStream
with the given entries
contents. This InputStream
may be closed: Nothing
happens in that case, because an actual close would invalidate
the underlying TarArchiveInputStream
.java.io.IOException
protected java.io.InputStream getInputStream(java.io.File file) throws java.io.IOException
java.io.IOException
private java.io.InputStream getInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry) throws java.io.IOException
java.io.IOException
private void open() throws java.io.IOException
java.io.IOException
private boolean findEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry) throws java.io.IOException
java.io.IOException