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 |
Definition at line 45 of file ZipMe.java.
|
New ZipMe object Definition at line 74 of file ZipMe.java. 00075 { 00076 }
|
|
Same as above but the place where to put the zip file is explicit
Definition at line 118 of file ZipMe.java. 00120 { 00121 create(putMeThere + File.separator + zipname, rootdir); 00122 }
|
|
Create a zip file from directory
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 }
|
|
Expand the content of the zip file
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 }
|
|
Same as below but the place where to get the zip file is explicit
Definition at line 132 of file ZipMe.java. 00134 { 00135 expand(getMeThere + File.separator + zipname, targetdir); 00136 }
|
|
Definition at line 294 of file ZipMe.java. 00295 {
00296 return useCompression;
00297 }
|
|
Get the size of the zip file
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 }
|
|
Definition at line 302 of file ZipMe.java. 00303 {
00304 this.useCompression = useCompression;
00305 }
|
|
Initial value: Trace .getLogger(ZipMe.class .getName()) Definition at line 67 of file ZipMe.java. |