private File zipFiles()

in aws-codedeploy-agent/src/main/java/jetbrains/buildServer/runner/codedeploy/ApplicationRevision.java [112:150]


  private File zipFiles(@NotNull List<File> files, @NotNull File destZip) throws CodeDeployRunner.CodeDeployRunnerException {
    log("Packaging " + files.size() + " files to application revision " + destZip);

    ZipOutputStream zipOutput = null;
    try {
      zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destZip)));
      byte[] buffer = new byte[64 * 1024];

      for (File f : files) {

        final ZipEntry zipEntry = new ZipEntry(getZipPath(f));
        zipEntry.setTime(f.lastModified());
        zipOutput.putNextEntry(zipEntry);

        final InputStream input = new BufferedInputStream(new FileInputStream(f));

        try {
          int read;
          do {
            read = input.read(buffer);
            zipOutput.write(buffer, 0, Math.max(read, 0));
          } while (read == buffer.length);
        } catch (IOException e) {
          throw new CodeDeployRunner.CodeDeployRunnerException("Failed to package file " + f + " to application revision " + destZip, e);
        } finally {
          FileUtil.close(input);
          zipOutput.closeEntry();
        }
      }
    } catch (Throwable t) {
      if (t instanceof CodeDeployRunner.CodeDeployRunnerException) {
        throw (CodeDeployRunner.CodeDeployRunnerException) t;
      }
      throw new CodeDeployRunner.CodeDeployRunnerException("Failed to package application revision " + destZip, t);
    } finally {
      FileUtil.close(zipOutput);
    }
    return destZip;
  }