private void zipFile(ZipOutputStream zip, String path) {
    try {
      FSDataInputStream in = getApi().open(path);
      zip.putNextEntry(new ZipEntry(path.substring(1)));
      byte[] chunk = new byte[1024];

      int readLen = 0;
      while(readLen != -1) {
        zip.write(chunk, 0, readLen);
        readLen = in.read(chunk);
      }
    } catch (IOException ex) {
      LOG.error("Error zipping file {}  (file ignored): ", path, ex);
    } catch (InterruptedException ex) {
      LOG.error("Error zipping file {} (file ignored): ", path, ex);
    } finally {
      try {
        zip.closeEntry();
      } catch (IOException ex) {
        LOG.error("Error closing entry {} (file ignored): ", path, ex);
      }
    }
  }
Download entire file
@param path path to file
@param download download as octet strem or as file mime type
@param checkperm used to check if the file can be downloaded. Takes precedence when both download and checkperm
                 is set.
@param headers http headers
@param ui uri info
@return response with file
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java