예제 #1
0
파일: Zip.java 프로젝트: amicom/my-project
 private java.util.List<File> addFolderToZip(String path, String srcFolder, ZipOutputStream zip)
     throws Exception {
   ArrayList<File> ret = new ArrayList<File>();
   File folder = new File(srcFolder);
   if (excludeFiles.contains(folder)) {
     return ret;
   }
   for (String fileName : folder.list()) {
     if (excludeFilter != null) {
       if (Regex.matches(fileName, excludeFilter)) {
         System.out.println("Filtered: " + fileName);
         continue;
       }
     }
     if (path.equals("")) {
       ret.addAll(addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip));
     } else {
       ret.addAll(addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip));
     }
   }
   return ret;
 }
예제 #2
0
파일: Zip.java 프로젝트: amicom/my-project
  private java.util.List<File> addFileToZip(String path, String srcFile, ZipOutputStream zip)
      throws Exception {
    ArrayList<File> ret = new ArrayList<File>();
    if (srcFile.endsWith("Thumbs.db")) {
      return null;
    }
    if (excludeFilter != null) {
      if (Regex.matches(srcFile, excludeFilter)) {

        System.out.println("Filtered: " + srcFile);
        return ret;
      }
    }
    File folder = new File(srcFile);
    if (excludeFiles != null && excludeFiles.contains(folder)) {
      return ret;
    }
    if (folder.isDirectory()) {
      ret.addAll(addFolderToZip(path, srcFile, zip));
      if (this.deleteAfterPack) FileCreationManager.getInstance().delete(new File(srcFile), null);
    } else {
      byte[] buf = new byte[1024];
      int len;
      FileInputStream in = new FileInputStream(srcFile);
      if (path == null || path.trim().length() == 0) {
        zip.putNextEntry(new ZipEntry(folder.getName()));
      } else {
        zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
      }

      while ((len = in.read(buf)) > 0) {
        zip.write(buf, 0, len);
      }
      in.close();
      if (this.deleteAfterPack) FileCreationManager.getInstance().delete(new File(srcFile), null);
      ret.add(new File(srcFile));
    }
    return ret;
  }