gov.nih.nci.cagrid.common
Class ZipUtilities

java.lang.Object
  extended by gov.nih.nci.cagrid.common.ZipUtilities

public class ZipUtilities
extends java.lang.Object

ZipUtilities Utilities to maniuplate zip files

Version:
$Id: ZipUtilities.java,v 1.6 2008/01/11 15:49:48 dervin Exp $
Author:
David W. Ervin *

Constructor Summary
ZipUtilities()
           
 
Method Summary
static byte[] extractEntryContents(java.io.File zipFile, java.lang.String entryName)
          Extracts the contents of a zip file entry to a byte array
static void insertEntry(java.io.File zipFile, java.lang.String entryName, byte[] data)
          Inserts an entry in a Zip file.
static void unzip(java.io.File zip, java.io.File location)
          Unzips a zip compressed file to a specific directory
static void unzipInPlace(java.io.File zip)
          Unzips a zip compressed file in the directory it resides in
static void zipDirectory(java.io.File dir, java.io.File zipFile)
          Applies zip compression to a directory and all its contents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipUtilities

public ZipUtilities()
Method Detail

unzip

public static void unzip(java.io.File zip,
                         java.io.File location)
                  throws java.io.IOException
Unzips a zip compressed file to a specific directory

Parameters:
zip - The zip compressed file
location - The location to unzip into
Throws:
java.io.IOException

unzipInPlace

public static void unzipInPlace(java.io.File zip)
                         throws java.io.IOException
Unzips a zip compressed file in the directory it resides in

Parameters:
zip - The zip compressed file
Throws:
java.io.IOException

zipDirectory

public static void zipDirectory(java.io.File dir,
                                java.io.File zipFile)
                         throws java.io.IOException
Applies zip compression to a directory and all its contents

Parameters:
dir - The directory to compress
zipFile - The file to create the zip archive in
Throws:
java.io.IOException

extractEntryContents

public static byte[] extractEntryContents(java.io.File zipFile,
                                          java.lang.String entryName)
                                   throws java.io.IOException
Extracts the contents of a zip file entry to a byte array

Parameters:
zipFile - The zip file
entryName - The name of the entry to extract
Returns:
A byte array containing the (uncompressed) contents of the entry
Throws:
java.io.IOException

insertEntry

public static void insertEntry(java.io.File zipFile,
                               java.lang.String entryName,
                               byte[] data)
                        throws java.io.IOException
Inserts an entry in a Zip file. If an entry with the given name is found, it will be replaced with the new one.

Parameters:
zipFile - The zip file to be appended
entryName - The name of the new entry
data - The data to add to the zip
Throws:
java.io.IOException