com.xmlmind.util Class Zip

java.lang.Object
com.xmlmind.util.Zip


public final class Zipextends java.lang.Object

Utility class which makes it easier zipping and unzipping files. Also works for .jar archives.

Nested Class Summary
static class Zip.Archive
This class allows a fine-grained control on the files to be added to the zip archive.

Method Summary
static long computeCRC(java.io.File file)
Utility: computes and returns the CRC-32 of specified file.
static void unzip(java.io.File srcFile, java.io.File dstDir)
Extracts files contained in specified stream to specified directory.
static void unzip(java.util.zip.ZipInputStream zip, java.io.File dstDir)
Extracts file contained in specified stream to specified directory.
static void zip(java.io.File srcDir, boolean includingTopDir, java.io.FilenameFilter filter, java.io.File dstFile)
Creates a zip archive containing the content of specified directory.

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail

zip

public static void zip(java.io.File srcDir,
boolean includingTopDir,
java.io.FilenameFilter filter,
java.io.File dstFile)
throws java.io.IOException
Creates a zip archive containing the content of specified directory.

Parameters:
srcDir - directory containing the files to be zipped. This directory is traversed recursively.
includingTopDir - if true, the basename of the top directory also appears in the created zip archive. Example: if C:\foo\bar is to be zipped and this option is true, all the paths contained in the zip archive will start with "bar/".
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.
dstFile - zip archive to be created
Throws:
java.io.IOException - if there is an I/O problem during the creation of the zip archive

computeCRC

public static final long computeCRC(java.io.File file)
throws java.io.IOException
Utility: computes and returns the CRC-32 of specified file.

Throws:
java.io.IOException

unzip

public static void unzip(java.io.File srcFile,
java.io.File dstDir)
throws java.io.IOException
Extracts files contained in specified stream to specified directory.

Closes input stream when done.

Parameters:
srcFile - source Zip file from which to extract files
dstDir - directory where files are to be extracted
Throws:
java.io.IOException - if an I/O problem occurs during the extraction of files

unzip

public static void unzip(java.util.zip.ZipInputStream zip,
java.io.File dstDir)
throws java.io.IOException
Extracts file contained in specified stream to specified directory.

Does not close zip input stream when done.

Parameters:
zip - zip stream or jar stream from which to extract files
dstDir - directory where files are to be extracted
Throws:
java.io.IOException - if an I/O problem occurs during the extraction of files