コード例 #1
0
  public String createBundle(String apiproxydir) throws IOException {

    System.out.println("apiproxydir" + apiproxydir);
    File dirObj = new File(apiproxydir);
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("apiproxy" + ".zip"));

    addDir(dirObj, out);
    out.close();

    return null;
  }
コード例 #2
0
  public void addToZipFile(String fileName, ZipOutputStream zos)
      throws FileNotFoundException, IOException {

    System.out.println("Writing '" + fileName + "' to zip file");

    File file = new File(fileName);
    FileInputStream fis = new FileInputStream(file);

    zos.putNextEntry(new ZipEntry(new File(fileName).getName()));

    byte[] bytes = new byte[1024];
    int length;
    while ((length = fis.read(bytes)) >= 0) {
      zos.write(bytes, 0, length);
    }

    zos.closeEntry();
    fis.close();
  }
コード例 #3
0
  static void addDir(File dirObj, ZipOutputStream out) throws IOException {
    File[] files = dirObj.listFiles();
    byte[] tmpBuf = new byte[1024];

    assert files != null;
    for (File file : files) {
      if (file.isDirectory()) {
        addDir(file, out);
        continue;
      }
      FileInputStream in = new FileInputStream(file.getPath());
      System.out.println(" Adding: " + file.getPath());
      out.putNextEntry(new ZipEntry(file.getPath()));
      int len;
      while ((len = in.read(tmpBuf)) > 0) {
        out.write(tmpBuf, 0, len);
      }
      out.closeEntry();
      in.close();
    }
  }