com.xmlmind.util
Class Zip.Archive

java.lang.Object
  extended by com.xmlmind.util.Zip.Archive
Enclosing class:
Zip

public static final class Zip.Archive
extends java.lang.Object

This class allows a fine-grained control on the files to be added to the zip archive.


Constructor Summary
Zip.Archive(java.util.zip.ZipOutputStream zip)
          Constructs a helper class which will allow to add files to the specified destination zip stream.
 
Method Summary
 void add(java.io.File srcFile, java.io.File baseDir)
          Equivalent to add(srcFile, baseDir, false).
 void add(java.io.File srcFile, java.io.File baseDir, boolean store)
          Adds specified file to the zip archive.
 void addAll(java.io.File srcDir, java.io.FilenameFilter filter, java.io.File baseDir)
          Adds all files contained in specified directory to the zip archive.
 void close()
          Closes both the underlying destination zip stream and its output stream.
 void finish()
          Closes the underlying destination zip stream without closing its output stream.
 java.util.zip.ZipOutputStream getZipOutputStream()
          Returns the underlying destination zip stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Zip.Archive

public Zip.Archive(java.util.zip.ZipOutputStream zip)
Constructs a helper class which will allow to add files to the specified destination zip stream.

Method Detail

getZipOutputStream

public java.util.zip.ZipOutputStream getZipOutputStream()
Returns the underlying destination zip stream.


add

public void add(java.io.File srcFile,
                java.io.File baseDir)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Equivalent to add(srcFile, baseDir, false).

Throws:
java.io.IOException
java.lang.IllegalArgumentException

add

public void add(java.io.File srcFile,
                java.io.File baseDir,
                boolean store)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Adds specified file to the zip archive.

Will automatically add directory entries if needed to. For example, when adding "/tmp/foo/bar/gee.txt" relatively to "/tmp", it will automatically add directory entries "foo/" and "foo/bar/".

Note that this method does not check that a source file is added only once to the archive. It is the resposability of the client code to check this.

Parameters:
srcFile - file or directory to be added
baseDir - ancestor directory of srcFile. Used to compute the path used to access srcFile in the zip archive.

Example: if srcFile is C:\temp\doc\chapter1\chapter1.xml and baseDir is C:\temp\doc, the zip archive will contain path chapter1/chapter1.xml.

store - if true, just store, that is do not compress, specified file. Ignored if srcFile is a directory.
Throws:
java.io.IOException - if there is an I/O problem during the creation of the zip archive
java.lang.IllegalArgumentException - if baseDir does not seem to be an ancestor directory of srcFile. Note that this may happen simply because baseDir and/or srcFile are not in canonical form

finish

public void finish()
            throws java.io.IOException
Closes the underlying destination zip stream without closing its output stream. Equivalent to getZipOutputStream().finish().

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes both the underlying destination zip stream and its output stream. Equivalent to getZipOutputStream().close().

Throws:
java.io.IOException

addAll

public void addAll(java.io.File srcDir,
                   java.io.FilenameFilter filter,
                   java.io.File baseDir)
            throws java.io.IOException
Adds all files contained in specified directory to the zip archive.

Parameters:
srcDir - directory containing the files to be zipped. This directory is traversed recursively.
filter - may be used to filter the files to be zipped. May be null, in which case, all the files and directory contained in srcDir are to be zipped.
baseDir - ancestor directory of srcDir. May be equal to srcDir. Used to compute the paths used to access the files coming from srcDir in the zip archive.
Throws:
java.io.IOException - if there is an I/O problem during the creation of the zip archive
See Also:
add(java.io.File, java.io.File)