TrueZIP 6.8

de.schlichtherle.io.archive.tar
Class TarDriver

java.lang.Object
  extended by de.schlichtherle.io.archive.spi.AbstractArchiveDriver
      extended by de.schlichtherle.io.archive.tar.TarDriver
All Implemented Interfaces:
ArchiveDriver, Serializable
Direct Known Subclasses:
TarBZip2Driver, TarGZipDriver

public class TarDriver
extends AbstractArchiveDriver

An archive driver which builds TAR files.

Instances of this class are immutable.

Since:
TrueZIP 6.0
Version:
$Id: TarDriver.java,v 1.4 2010/08/20 13:09:44 christian_schlichtherle Exp $
Author:
Christian Schlichtherle
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class de.schlichtherle.io.archive.spi.AbstractArchiveDriver
AbstractArchiveDriver.InconsistentCharsetSupportError
 
Field Summary
static String DEFAULT_CHARSET
          The character set to use for entry names, which is "US-ASCII".
 
Constructor Summary
TarDriver()
          Equivalent to this(DEFAULT_CHARSET, null, null).
TarDriver(String charset)
          Equivalent to this(charset, null, null).
TarDriver(String charset, Icon openIcon, Icon closedIcon)
          Constructs a new TAR driver.
 
Method Summary
 ArchiveEntry createArchiveEntry(Archive archive, String entryName, ArchiveEntry template)
          Creates a new archive entry for entryName for use with an OutputArchive.
 InputArchive createInputArchive(Archive archive, ReadOnlyFile rof)
          Creates a new input archive for archive from the given read only file.
protected  InputStream createInputStream(Archive archive, ReadOnlyFile rof)
          Returns a new InputStream to read the contents from the given ReadOnlyFile from.
 OutputArchive createOutputArchive(Archive archive, OutputStream out, InputArchive source)
          Creates a new output archive for archive from the given output stream.
protected  TarInputArchive createTarInputArchive(Archive archive, InputStream in)
          Returns a new TarInputArchive to read the contents from the given InputStream.
protected  TarOutputArchive createTarOutputArchive(Archive archive, OutputStream out, TarInputArchive source)
           
 
Methods inherited from class de.schlichtherle.io.archive.spi.AbstractArchiveDriver
ensureEncodable, getCharset, getClosedIcon, getEncoding, getOpenIcon
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.schlichtherle.io.archive.spi.ArchiveDriver
equals, hashCode
 

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
The character set to use for entry names, which is "US-ASCII". TAR files should actually be able to use the system's native character set charset. However, the low level TAR code as of Ant 1.6.5 doesn't support that, hence this constraint.

See Also:
Constant Field Values
Constructor Detail

TarDriver

public TarDriver()
Equivalent to this(DEFAULT_CHARSET, null, null).


TarDriver

public TarDriver(String charset)
Equivalent to this(charset, null, null).


TarDriver

public TarDriver(String charset,
                 Icon openIcon,
                 Icon closedIcon)
Constructs a new TAR driver.

Parameters:
charset - The name of a character set to use for all entry names when reading or writing TAR files. Warning: Due to limitations in Apache's Ant code, using anything else than "US-ASCII" is currently not supported!
Method Detail

createArchiveEntry

public ArchiveEntry createArchiveEntry(Archive archive,
                                       String entryName,
                                       ArchiveEntry template)
                                throws CharConversionException
Description copied from interface: ArchiveDriver
Creates a new archive entry for entryName for use with an OutputArchive.

Parameters:
archive - The abstract archive representation which TrueZIP's internal ArchiveController is processing - never null.
entryName - A valid archive entry name - never null.
template - If not null, then the newly created entry shall inherit as much attributes from this object as possible (with the exception of the name). This is typically used for archive copy operations. Note that there is no guarantee on the runtime type of this object; it may have been created by other drivers. It is safe to ignore the metaData property when copying entries.
Returns:
A new archive entry instance.
Throws:
CharConversionException - If name contains illegal characters.
See Also:
Requirements for Archive Entry Names

createInputArchive

public InputArchive createInputArchive(Archive archive,
                                       ReadOnlyFile rof)
                                throws IOException
Creates a new input archive for archive from the given read only file.

Note that if an exception is thrown, the method must be reentrant! In addition, the exception type determines the behaviour of the classes File, FileInputStream and FileOutputStream as follows:

Exception type File.isFile() File.isDirectory() File.exists() File.delete()
FileNotFoundException false false true true (unless prohibited by the real file system)
IOException true false true true (unless prohibited by the real file system)

This implementation calls createInputStream(archive, rof) and passes the resulting stream to createTarInputArchive(Archive, InputStream).

Parameters:
archive - The abstract archive representation which TrueZIP's internal ArchiveController is processing - never null.
rof - The ReadOnlyFile to read the actual archive contents from - never null. Hint: If you'ld prefer to have an InputStream, you could decorate this parameter with a ReadOnlyFileInputStream.
Returns:
A new input archive instance.
Throws:
TransientIOException - If calling this method for the same archive file again may finally succeed. This exception is associated with another IOException as its cause which is unwrapped and interpreted as below.
FileNotFoundException - If the input archive is inaccessible for any reason and you would like the package de.schlichtherle.io to mask the archive as a special file which cannot get read, written or deleted.
IOException - On any other I/O or data format related issue when reading the input archive and you would like the package de.schlichtherle.io to treat the archive like a regular file which may be read, written or deleted.
See Also:
InputArchive

createInputStream

protected InputStream createInputStream(Archive archive,
                                        ReadOnlyFile rof)
                                 throws IOException
Returns a new InputStream to read the contents from the given ReadOnlyFile from. Override this method in order to decorate the stream returned by the implementation in this class in order to have the driver read the TAR file from wrapper file formats such as GZIP or BZIP2.

Note that the returned stream should support marking for best performance and will always be closed early by createInputArchive(Archive, ReadOnlyFile).

Throws:
IOException

createTarInputArchive

protected TarInputArchive createTarInputArchive(Archive archive,
                                                InputStream in)
                                         throws IOException
Returns a new TarInputArchive to read the contents from the given InputStream. The implementation in this class simply returns new TarInputArchive(in).

Throws:
IOException

createOutputArchive

public OutputArchive createOutputArchive(Archive archive,
                                         OutputStream out,
                                         InputArchive source)
                                  throws IOException
Creates a new output archive for archive from the given output stream.

This implementation forwards the call to createTarOutputArchive(de.schlichtherle.io.archive.Archive, java.io.OutputStream, de.schlichtherle.io.archive.tar.TarInputArchive) and wraps the result in a new MultiplexedOutputArchive.

Parameters:
archive - The abstract archive representation which TrueZIP's internal ArchiveController is processing - never null.
out - The OutputStream to write the archive entries to - never null.
source - The source InputArchive if archive is going to get updated. If not null, this is guaranteed to be a product of this driver's ArchiveDriver.createInputArchive(de.schlichtherle.io.archive.Archive, de.schlichtherle.io.rof.ReadOnlyFile) method. This may be used to copy some meta data which is specific to the type of archive this driver supports. For example, this could be used to copy the comment of a ZIP file.
Returns:
A new output archive instance.
Throws:
TransientIOException - If calling this method for the same archive file again may finally succeed. This exception is associated with another IOException as its cause which is unwrapped and interpreted as below.
FileNotFoundException - If the output archive is inaccessible for any reason.
IOException - On any other I/O or data format related issue when writing the output archive.
See Also:
OutputArchive

createTarOutputArchive

protected TarOutputArchive createTarOutputArchive(Archive archive,
                                                  OutputStream out,
                                                  TarInputArchive source)
                                           throws IOException
Throws:
IOException

TrueZIP 6.8

Copyright © 2005-2010 Schlichtherle IT Services. All Rights Reserved.