public class TarFile extends 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(TarEntry)
only for the current entry. Basically, this is to handle it like
TarInputStream
.
The advantage of this class is that you may write code for the
ArchiveFile
, which is valid for both tar files and zip files.
ArchiveFile.Entry
Constructor and Description |
---|
TarFile(File file)
Creates a new instance with the given file.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
Enumeration |
getEntries()
Implementation of
ArchiveFile.getEntries() . |
InputStream |
getInputStream(ArchiveFile.Entry entry)
Returns an
InputStream with the given entries contents. |
protected InputStream |
getInputStream(File file) |
InputStream |
getInputStream(TarEntry entry)
Returns an
InputStream with the given entries
contents. |
public TarFile(File file)
public Enumeration getEntries() throws IOException
ArchiveFile.getEntries()
. Note, that there is
an interaction between this method and getInputStream(TarEntry)
,
or getInputStream(org.codehaus.plexus.archiver.ArchiveFile.Entry)
:
If an input stream is opened for any other entry than the enumerations
current entry, then entries may be skipped.getEntries
in interface ArchiveFile
IOException
public void close() throws IOException
IOException
public InputStream getInputStream(ArchiveFile.Entry entry) throws IOException
ArchiveFile
InputStream
with the given entries contents.getInputStream
in interface ArchiveFile
IOException
public InputStream getInputStream(TarEntry entry) throws 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 TarInputStream
.IOException
protected InputStream getInputStream(File file) throws IOException
IOException
Copyright © 2008-2012 Sonatype, Inc.. All Rights Reserved.