org.objectweb.cjdbc.common.util
Class Zipper

java.lang.Object
  extended byorg.objectweb.cjdbc.common.util.Zipper

public class Zipper
extends java.lang.Object

Zip utility class to compress a directory into a single zip file and vice-versa.

Author:
Emmanuel Cecchet, Nicolas Modrzyk

Field Summary
private static int BUFFER_SIZE
           
(package private) static Trace logger
           
static int STORE_FULL_PATH_IN_ZIP
          Store full path in zip when archiving
static int STORE_NAME_ONLY_IN_ZIP
          Store only file names in zip when archiving
static int STORE_PATH_FROM_ZIP_ROOT
          Store path relative to root directory in zip when archiving
static int STORE_RELATIVE_PATH_IN_ZIP
          Store relative path in zip when archiving
static java.lang.String ZIP_EXT
          Extension for zipped file names
 
Constructor Summary
Zipper()
           
 
Method Summary
private static void directoryWalker(java.lang.String currentDir, java.lang.String rootDir, java.util.zip.ZipOutputStream zos, int storePolicy)
          Walk through currentDir and recursively in its subdirectories.
static void unzip(java.lang.String zipName, java.lang.String targetDir)
          Expand the content of the zip file
static void zip(java.lang.String zipName, java.lang.String rootDir, int storePolicy)
          Create a zip file from directory
private static void zipFile(java.lang.String filePath, java.util.zip.ZipOutputStream zos, int storePolicy, java.lang.String rootDir)
          TODO: zipFunc definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZIP_EXT

public static final java.lang.String ZIP_EXT
Extension for zipped file names

See Also:
Constant Field Values

BUFFER_SIZE

private static final int BUFFER_SIZE
See Also:
Constant Field Values

STORE_FULL_PATH_IN_ZIP

public static final int STORE_FULL_PATH_IN_ZIP
Store full path in zip when archiving

See Also:
Constant Field Values

STORE_NAME_ONLY_IN_ZIP

public static final int STORE_NAME_ONLY_IN_ZIP
Store only file names in zip when archiving

See Also:
Constant Field Values

STORE_RELATIVE_PATH_IN_ZIP

public static final int STORE_RELATIVE_PATH_IN_ZIP
Store relative path in zip when archiving

See Also:
Constant Field Values

STORE_PATH_FROM_ZIP_ROOT

public static final int STORE_PATH_FROM_ZIP_ROOT
Store path relative to root directory in zip when archiving

See Also:
Constant Field Values

logger

static Trace logger
Constructor Detail

Zipper

public Zipper()
Method Detail

zip

public static void zip(java.lang.String zipName,
                       java.lang.String rootDir,
                       int storePolicy)
                throws java.lang.Exception
Create a zip file from directory

Parameters:
zipName - name of the file to create
rootDir - root directory to archive
storePolicy - the store policy to use (STORE_FULL_PATH_IN_ZIP, STORE_NAME_ONLY_IN_ZIP, STORE_RELATIVE_PATH_IN_ZIP or STORE_PATH_FROM_ZIP_ROOT)
Throws:
java.lang.Exception - if fails

unzip

public static void unzip(java.lang.String zipName,
                         java.lang.String targetDir)
                  throws java.lang.Exception
Expand the content of the zip file

Parameters:
zipName - of the file to expand
targetDir - where to place unzipped files
Throws:
java.lang.Exception - if fails

directoryWalker

private static void directoryWalker(java.lang.String currentDir,
                                    java.lang.String rootDir,
                                    java.util.zip.ZipOutputStream zos,
                                    int storePolicy)
                             throws java.io.IOException
Walk through currentDir and recursively in its subdirectories. Each file found is zipped.

Parameters:
currentDir - directory to walk through
rootDir - root directory for path references
zos - ZipOutputSteam to write to
storePolicy - file path storing policy
Throws:
java.io.IOException - if an error occurs

zipFile

private static void zipFile(java.lang.String filePath,
                            java.util.zip.ZipOutputStream zos,
                            int storePolicy,
                            java.lang.String rootDir)
                     throws java.io.IOException
TODO: zipFunc definition.

Parameters:
filePath - file to compress
zos - ZipOutputSteam to write to
storePolicy - file path storing policy
rootDir - root directory for path references
Throws:
java.io.IOException - if an error occurs


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.