org.codehaus.plexus.archiver.tar
Class TarFile

java.lang.Object
  extended by org.codehaus.plexus.archiver.tar.TarFile
All Implemented Interfaces:
ArchiveFile
Direct Known Subclasses:
BZip2TarFile, GZipTarFile

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(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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.codehaus.plexus.archiver.ArchiveFile
ArchiveFile.Entry
 
Constructor Summary
TarFile(java.io.File file)
          Creates a new instance with the given file.
 
Method Summary
 void close()
           
 java.util.Enumeration getEntries()
          Implementation of ArchiveFile.getEntries().
 java.io.InputStream getInputStream(ArchiveFile.Entry entry)
          Returns an InputStream with the given entries contents.
protected  java.io.InputStream getInputStream(java.io.File file)
           
 java.io.InputStream getInputStream(TarEntry entry)
          Returns an InputStream with the given entries contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TarFile

public TarFile(java.io.File file)
Creates a new instance with the given file.

Method Detail

getEntries

public java.util.Enumeration getEntries()
                                 throws java.io.IOException
Implementation of 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.

Specified by:
getEntries in interface ArchiveFile
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream(ArchiveFile.Entry entry)
                                   throws java.io.IOException
Description copied from interface: ArchiveFile
Returns an InputStream with the given entries contents.

Specified by:
getInputStream in interface ArchiveFile
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream(TarEntry entry)
                                   throws java.io.IOException
Returns an 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.

Throws:
java.io.IOException

getInputStream

protected java.io.InputStream getInputStream(java.io.File file)
                                      throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2001-2010 Codehaus. All Rights Reserved.