Example #1
0
  private static void packZip(File output, List<File> sources) throws IOException {
    ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output));
    zipOut.setLevel(Deflater.DEFAULT_COMPRESSION);

    for (File source : sources) {
      if (source.isDirectory()) {
        zipDir(zipOut, "", source);
      } else {
        zipFile(zipOut, "", source);
      }
    }

    zipOut.flush();
    zipOut.close();
    mcMMO.p.getLogger().info("Backup Completed.");
  }
Example #2
0
  private static void zipDir(ZipOutputStream zos, String path, File dir) throws IOException {
    if (!dir.canRead()) {
      System.out.println(
          "Cannot read " + dir.getCanonicalPath() + " (Maybe because of permissions?)");
      return;
    }

    File[] files = dir.listFiles();
    path = buildPath(path, dir.getName());

    for (File source : files) {
      if (source.isDirectory()) {
        zipDir(zos, path, source);
      } else {
        zipFile(zos, path, source);
      }
    }
  }