Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.util.ZipMe Class Reference

List of all members.

Public Member Functions

 ZipMe ()
void create (String zipname, String rootdir) throws Exception
void create (String zipname, String rootdir, String putMeThere) throws Exception
void expand (String zipname, String targetdir, String getMeThere) throws Exception
long getZipSize ()
void expand (String zipname, String targetdir) throws Exception
boolean getUseCompression ()
void setUseCompression (boolean useCompression)

Static Package Attributes

final int BUFFER = 2048
final int STORE_FULL_PATH_IN_ZIP = 0
final int STORE_NAME_ONLY_IN_ZIP = 1
final int STORE_RELATIVE_PATH_IN_ZIP = 2
final int STORE_PATH_FROM_ZIP_ROOT = 3
final int STORE_POLICY = STORE_PATH_FROM_ZIP_ROOT
Trace logger

Detailed Description

Zip utility class inspired by the java tutorials of sun.

Author:
Nicolas Modrzyk

Definition at line 45 of file ZipMe.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.util.ZipMe.ZipMe  ) 
 

New ZipMe object

Definition at line 74 of file ZipMe.java.

00075   {
00076   }


Member Function Documentation

void org.objectweb.cjdbc.common.util.ZipMe.create String  zipname,
String  rootdir,
String  putMeThere
throws Exception
 

Same as above but the place where to put the zip file is explicit

Parameters:
zipname of the file to create
rootdir of the directory to archive
putMeThere please
Exceptions:
Exception if fails

Definition at line 118 of file ZipMe.java.

00120   {
00121     create(putMeThere + File.separator + zipname, rootdir);
00122   }

void org.objectweb.cjdbc.common.util.ZipMe.create String  zipname,
String  rootdir
throws Exception
 

Create a zip file from directory

Parameters:
zipname of the file to create
rootdir of the directory to archive
Exceptions:
Exception if fails

Definition at line 85 of file ZipMe.java.

00086   {
00087     if (zipname == null || rootdir == null)
00088       throw new Exception("Invalid arguments to create zip file");
00089     this.rootDir = rootdir;
00090     try
00091     {
00092       zipPath = zipname + Constants.ZIP_EXT;
00093       fos = new FileOutputStream(zipPath);
00094       zos = new ZipOutputStream(fos);
00095 
00096       dirFunc(rootdir);
00097 
00098       zos.flush();
00099       zos.finish();
00100       zos.close();
00101       fos.close();
00102     }
00103     catch (IOException e)
00104     {
00105       logger.error(e.getMessage());
00106       throw e;
00107     }
00108   }

void org.objectweb.cjdbc.common.util.ZipMe.expand String  zipname,
String  targetdir
throws Exception
 

Expand the content of the zip file

Parameters:
zipname of the file to expand
targetdir where to place unzipped files
Exceptions:
Exception if fails

Definition at line 159 of file ZipMe.java.

00160   {
00161     File ftargetDir = new File(targetdir);
00162     if (!ftargetDir.exists())
00163       ftargetDir.mkdirs();
00164     if (!ftargetDir.exists())
00165       throw new Exception(Translate.get("zip.invalid.target.directory"));
00166 
00167     zipPath = zipname + Constants.ZIP_EXT;
00168     File fzipname = new File(zipPath);
00169     if (!fzipname.exists())
00170       throw new Exception(Translate.get("zip.invalid.source.file", zipname));
00171 
00172     try
00173     {
00174       fis = new FileInputStream(fzipname);
00175       zis = new ZipInputStream(fis);
00176       
00177       ZipEntry entry;
00178 
00179       byte data[] = new byte[BUFFER];
00180       while ((entry = zis.getNextEntry()) != null)
00181       {
00182         int count;
00183         String target = targetdir + File.separator + entry.getName();
00184         File fget = new File(target);
00185         fget.mkdirs(); // create needed new directories
00186         fget.delete(); // delete directory but not parents
00187         if (logger.isDebugEnabled())
00188           logger.debug(Translate.get("zip.extracting", new String[]{
00189               String.valueOf(entry), fget.getAbsolutePath()}));
00190         fos = new FileOutputStream(target);
00191 
00192         dest = new BufferedOutputStream(fos, BUFFER);
00193         while ((count = zis.read(data, 0, BUFFER)) != -1)
00194         {
00195           dest.write(data, 0, count);
00196         }
00197         dest.flush();
00198         dest.close();
00199       }
00200       zis.close();
00201     }
00202     catch (Exception e)
00203     {
00204       e.printStackTrace();
00205       logger.error(e.getMessage());
00206       throw e;
00207     }
00208   }

void org.objectweb.cjdbc.common.util.ZipMe.expand String  zipname,
String  targetdir,
String  getMeThere
throws Exception
 

Same as below but the place where to get the zip file is explicit

Parameters:
zipname of the file to expand
targetdir where to place unzipped files
getMeThere please
Exceptions:
Exception if fails

Definition at line 132 of file ZipMe.java.

00134   {
00135     expand(getMeThere + File.separator + zipname, targetdir);
00136   }

boolean org.objectweb.cjdbc.common.util.ZipMe.getUseCompression  ) 
 

Returns:
Returns the useCompression.

Definition at line 294 of file ZipMe.java.

00295   {
00296     return useCompression;
00297   }

long org.objectweb.cjdbc.common.util.ZipMe.getZipSize  ) 
 

Get the size of the zip file

Returns:
size in bytes

Definition at line 143 of file ZipMe.java.

00144   {
00145     File f = new File(zipPath);
00146     if (f.exists())
00147       return f.length();
00148     else
00149       return -1;
00150   }

void org.objectweb.cjdbc.common.util.ZipMe.setUseCompression boolean  useCompression  ) 
 

Parameters:
useCompression The useCompression to set.

Definition at line 302 of file ZipMe.java.

00303   {
00304     this.useCompression = useCompression;
00305   }


Member Data Documentation

Trace org.objectweb.cjdbc.common.util.ZipMe.logger [static, package]
 

Initial value:

 Trace
                                                              .getLogger(ZipMe.class
                                                                  .getName())

Definition at line 67 of file ZipMe.java.


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:14 2005 for C-JDBC by  doxygen 1.3.9.1