de.schlichtherle.io.archive.zip
Class ZipDriver

java.lang.Object
  extended by de.schlichtherle.io.archive.spi.AbstractArchiveDriver
      extended by de.schlichtherle.io.archive.zip.ZipDriver
All Implemented Interfaces:
ArchiveDriver, Serializable
Direct Known Subclasses:
AbstractSfxDriver, CheckedZipDriver, JarDriver, Zip32Driver

public class ZipDriver
extends AbstractArchiveDriver

An archive driver which builds ZIP files. Note that this driver does not check the CRC value of any entries in existing archives.

Instances of this class are immutable.

Since:
TrueZIP 6.0
Version:
TrueZIP 6.7
Author:
Christian Schlichtherle
See Also:
CheckedZipDriver, 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 default character set to use for entry names and comments, which is "IBM437".
static int DEFAULT_LEVEL
          The default compression level to use when writing a ZIP output stream, which is 9.
 
Constructor Summary
ZipDriver()
          Equivalent to this(DEFAULT_CHARSET, null, null, false, false, DEFAULT_LEVEL).
ZipDriver(int level)
          Equivalent to this(DEFAULT_CHARSET, null, null, false, false, level).
ZipDriver(String charset)
          Equivalent to this(charset, null, null, false, false, DEFAULT_LEVEL).
ZipDriver(String charset, boolean preambled, boolean postambled, Icon openIcon, Icon closedIcon)
           
ZipDriver(String charset, Icon openIcon, Icon closedIcon, boolean preambled, boolean postambled, int level)
          Constructs a new ZIP 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.
 OutputArchive createOutputArchive(Archive archive, OutputStream out, InputArchive source)
          Creates a new output archive for archive from the given output stream.
protected  ZipInputArchive createZip32InputArchive(Archive archive, ReadOnlyFile rof)
          Deprecated. Use createZipInputArchive(de.schlichtherle.io.archive.Archive, de.schlichtherle.io.rof.ReadOnlyFile) instead.
protected  ZipOutputArchive createZip32OutputArchive(Archive archive, OutputStream out, ZipInputArchive source)
          Deprecated. Use createZipOutputArchive(de.schlichtherle.io.archive.Archive, java.io.OutputStream, de.schlichtherle.io.archive.zip.ZipInputArchive) instead.
protected  ZipEntry createZipEntry(String entryName)
           
protected  ZipEntry createZipEntry(ZipEntry template)
           
protected  ZipInputArchive createZipInputArchive(Archive archive, ReadOnlyFile rof)
           
protected  ZipOutputArchive createZipOutputArchive(Archive archive, OutputStream out, ZipInputArchive source)
           
 int getLevel()
          Returns the value of the property level which was provided to the constructor.
 boolean getPostambled()
          Returns the value of the property postambled which was provided to the constructor.
 boolean getPreambled()
          Returns the value of the property preambled which was provided to the constructor.
 
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 default character set to use for entry names and comments, which is "IBM437".

See Also:
Constant Field Values

DEFAULT_LEVEL

public static final int DEFAULT_LEVEL
The default compression level to use when writing a ZIP output stream, which is 9.

See Also:
Constant Field Values
Constructor Detail

ZipDriver

public ZipDriver()
Equivalent to this(DEFAULT_CHARSET, null, null, false, false, DEFAULT_LEVEL).


ZipDriver

public ZipDriver(String charset)
Equivalent to this(charset, null, null, false, false, DEFAULT_LEVEL).


ZipDriver

public ZipDriver(int level)
Equivalent to this(DEFAULT_CHARSET, null, null, false, false, level).


ZipDriver

public ZipDriver(String charset,
                 boolean preambled,
                 boolean postambled,
                 Icon openIcon,
                 Icon closedIcon)

ZipDriver

public ZipDriver(String charset,
                 Icon openIcon,
                 Icon closedIcon,
                 boolean preambled,
                 boolean postambled,
                 int level)
Constructs a new ZIP driver.

Parameters:
preambled - true if and only if a prospective ZIP compatible file is allowed to contain preamble data before the actual ZIP file data. Self Extracting Archives typically use the preamble to store the application code that is required to extract the ZIP file contents.

Please note that any ZIP compatible file may actually have a preamble. However, for performance reasons this parameter should be set to false, unless required.

postambled - true if and only if a prospective ZIP compatible file is allowed to have a postamble of arbitrary length. If set to false, the ZIP compatible file may still have a postamble. However, the postamble must not exceed 64KB size, including the End Of Central Directory record and thus the ZIP file comment. This causes the initial ZIP file compatibility test to fail fast if the file is not compatible to the ZIP File Format Specification. For performance reasons, this parameter should be set to false unless you need to support Self Extracting Archives with very large postambles.
level - The compression level to use when deflating an entry to a ZIP output stream.
Throws:
IllegalArgumentException - If level is not in the range [0, 9] and is not -1.
Method Detail

getPreambled

public final boolean getPreambled()
Returns the value of the property preambled which was provided to the constructor.


getPostambled

public final boolean getPostambled()
Returns the value of the property postambled which was provided to the constructor.


getLevel

public final int getLevel()
Returns the value of the property level which was provided to the constructor.


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

createZipEntry

protected ZipEntry createZipEntry(ZipEntry template)

createZipEntry

protected ZipEntry createZipEntry(String entryName)

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)

The implementation in ZipDriver simply forwards the call to createZipInputArchive(de.schlichtherle.io.archive.Archive, de.schlichtherle.io.rof.ReadOnlyFile).

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

createZipInputArchive

protected ZipInputArchive createZipInputArchive(Archive archive,
                                                ReadOnlyFile rof)
                                         throws IOException
Throws:
IOException

createZip32InputArchive

protected ZipInputArchive createZip32InputArchive(Archive archive,
                                                  ReadOnlyFile rof)
                                           throws IOException
Deprecated. Use createZipInputArchive(de.schlichtherle.io.archive.Archive, de.schlichtherle.io.rof.ReadOnlyFile) instead.

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.

The implementation in ZipDriver simply forwards the call to createZipOutputArchive(de.schlichtherle.io.archive.Archive, java.io.OutputStream, de.schlichtherle.io.archive.zip.ZipInputArchive) 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

createZipOutputArchive

protected ZipOutputArchive createZipOutputArchive(Archive archive,
                                                  OutputStream out,
                                                  ZipInputArchive source)
                                           throws IOException
Throws:
IOException

createZip32OutputArchive

protected ZipOutputArchive createZip32OutputArchive(Archive archive,
                                                    OutputStream out,
                                                    ZipInputArchive source)
                                             throws IOException
Deprecated. Use createZipOutputArchive(de.schlichtherle.io.archive.Archive, java.io.OutputStream, de.schlichtherle.io.archive.zip.ZipInputArchive) instead.

Throws:
IOException