Class TarFile
- java.lang.Object
-
- org.codehaus.plexus.archiver.tar.TarFile
-
- All Implemented Interfaces:
ArchiveFile
- Direct Known Subclasses:
BZip2TarFile,GZipTarFile,XZTarFile
public class TarFile extends java.lang.Object implements ArchiveFile
Implementation of
ArchiveFilefor 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 invokegetInputStream(TarArchiveEntry)only for the current entry. Basically, this is to handle it likeTarArchiveInputStream.The advantage of this class is that you may write code for the
ArchiveFile, which is valid for both tar files and zip files.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.commons.compress.archivers.tar.TarArchiveEntrycurrentEntryprivate java.io.Filefileprivate org.apache.commons.compress.archivers.tar.TarArchiveInputStreaminputStream
-
Constructor Summary
Constructors Constructor Description TarFile(java.io.File file)Creates a new instance with the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private booleanfindEntry(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 ofArchiveFile.getEntries().protected java.io.InputStreamgetInputStream(java.io.File file)java.io.InputStreamgetInputStream(org.apache.commons.compress.archivers.ArchiveEntry entry)Returns anInputStreamwith the given entries contents.java.io.InputStreamgetInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry)Returns anInputStreamwith the given entries contents.private java.io.InputStreamgetInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry)private voidopen()
-
-
-
Method Detail
-
getEntries
public java.util.Enumeration<org.apache.commons.compress.archivers.ArchiveEntry> getEntries() throws java.io.IOExceptionImplementation ofArchiveFile.getEntries(). Note, that there is an interaction between this method andgetInputStream(TarArchiveEntry), orgetInputStream(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.- Specified by:
getEntriesin interfaceArchiveFile- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream(org.apache.commons.compress.archivers.ArchiveEntry entry) throws java.io.IOExceptionDescription copied from interface:ArchiveFileReturns anInputStreamwith the given entries contents. org.apache.commons.compress.archivers.ArchiveEntry- Specified by:
getInputStreamin interfaceArchiveFile- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry) throws java.io.IOExceptionReturns anInputStreamwith the given entries contents. ThisInputStreammay be closed: Nothing happens in that case, because an actual close would invalidate the underlyingTarArchiveInputStream.- Throws:
java.io.IOException
-
getInputStream
protected java.io.InputStream getInputStream(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
getInputStream
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- Throws:
java.io.IOException
-
open
private void open() throws java.io.IOException- Throws:
java.io.IOException
-
findEntry
private boolean findEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, org.apache.commons.compress.archivers.tar.TarArchiveEntry currentEntry) throws java.io.IOException- Throws:
java.io.IOException
-
-