org.rhq.core.util
Class ZipUtil

java.lang.Object
  extended by org.rhq.core.util.ZipUtil

public abstract class ZipUtil
extends Object

A set of utility methods for working with zip files.

Author:
Ian Springer

Nested Class Summary
static interface ZipUtil.ZipEntryVisitor
          Used by walkZipFile(File, ZipEntryVisitor) to visit zip entries.
 
Method Summary
static void unzipFile(File zipFile, File destDir)
          Unzips the content of the given zip file to the specified directory.
static void unzipFile(InputStream zipContent, File outputDir)
          Writes the zip content out to the specified directory.
static void walkZipFile(File zipFile, ZipUtil.ZipEntryVisitor visitor)
          Walks the entries of a zip file, allowing a listener to "visit" each node and perform tasks on the zip entry.
static void zipFileOrDirectory(File fileOrDirToZip, File zipFile)
          Zips up the given file or directory and stores the zip file at zipFile.
static void zipFileOrDirectory(File fileOrDirToZip, ZipOutputStream zos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

zipFileOrDirectory

public static void zipFileOrDirectory(File fileOrDirToZip,
                                      File zipFile)
                               throws IOException
Zips up the given file or directory and stores the zip file at zipFile. Note that zipping up a directory and if the output zip file is to be located in or under the directory being zipped, an exception will be thrown - you must output the zip file in another location outside of the directory being zipped.

Parameters:
fileOrDirToZip - what to zip up
zipFile - where to store the zip file
Throws:
IOException

zipFileOrDirectory

public static void zipFileOrDirectory(File fileOrDirToZip,
                                      ZipOutputStream zos)
                               throws IOException
Throws:
IOException

unzipFile

public static void unzipFile(File zipFile,
                             File destDir)
                      throws IOException
Unzips the content of the given zip file to the specified directory.

Parameters:
zipFile - the zip file to unzip
destDir - root directory where the zip files will be extracted
Throws:
IOException - if any errors occur during the reading or writing

unzipFile

public static void unzipFile(InputStream zipContent,
                             File outputDir)
                      throws IOException
Writes the zip content out to the specified directory. The input stream should contain a valid ZIP archive that will be extracted. NOTE: zipContent will be closed by this method.

Parameters:
zipContent - stream containing the content to write; should be formatted as a ZIP file
outputDir - root directory where the zip files will be extracted
Throws:
IOException - if any errors occur during the reading or writing

walkZipFile

public static void walkZipFile(File zipFile,
                               ZipUtil.ZipEntryVisitor visitor)
                        throws Exception
Walks the entries of a zip file, allowing a listener to "visit" each node and perform tasks on the zip entry.

Parameters:
zipFile - the zip file to walk
visitor - the object that will be notified for each entry in the zip file
Throws:
Exception - if any errors occur during the reading or visiting


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.