Ejemplo n.º 1
0
 private void deflate(String tmpDir, String path) {
   String tmpFile = "tmp-" + Utils.timestamp() + ".zip";
   try {
     ZipFile zipFile = new ZipFile(tmpFile);
     ZipParameters parameters = new ZipParameters();
     parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
     parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
     parameters.setIncludeRootFolder(false);
     zipFile.addFolder(tmpDir, parameters);
   } catch (Exception e) {
     e.printStackTrace();
     return;
   }
   File from = null;
   File to = null;
   try {
     File target = new File(path);
     if (target.exists()) FileUtils.forceDelete(target);
     from = new File(tmpFile);
     to = new File(path);
     FileUtils.moveFile(from, to);
   } catch (IOException e) {
     Utils.onError(new Error.FileMove(tmpFile, path));
   }
   try {
     FileUtils.deleteDirectory(new File(tmpDir));
   } catch (IOException e) {
     Utils.log("can't delete temporary folder");
   }
 }
Ejemplo n.º 2
0
 private String inflate(String path) {
   if (!new File(path).canRead()) {
     Utils.onError(new Error.FileRead(path));
     return null;
   }
   String tmpDir = "tmp-" + Utils.timestamp();
   try {
     ZipFile zipFile = new ZipFile(path);
     zipFile.extractAll(tmpDir);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
   return tmpDir;
 }