title: Concurrently zipping and download file performance issues
body: <p>I have a servlet that compresses file while its downloading. My problem slow process is really slow. I'm zipping files coz files will be more than 1GB. But downloading process is so slow. What kind of betterment would you suggest me?</p>
  
  <pre><code>package mainpackage;
  
  import java.io.BufferedInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Properties;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipOutputStream;
  
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  public class DownloadZipServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
  
      public DownloadZipServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  
      protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("application/zip");
          response.setHeader("Content-Disposition",
                  "attachment;filename=download.zip");
  
          ServletOutputStream sos;
          ZipOutputStream zos;
          InputStream fis;
          List&lt;File&gt; filesToDownload = new ArrayList&lt;File&gt;();
  
          filesToDownload.add(new File(getDirectory(), "download.png"));
          filesToDownload.add(new File(getDirectory(), "downloadpdf.pdf"));
  
          sos = response.getOutputStream();
          zos = new ZipOutputStream(sos);
  
  
          for (File fileToSend : filesToDownload) {
  
              ZipEntry ze = new ZipEntry(fileToSend.getName());
              zos.putNextEntry(ze);
  
              fis = new BufferedInputStream(new FileInputStream(fileToSend));
              byte[] buffer = new byte[131072*100];
              int readBytesCount = 0;
              while ((readBytesCount = fis.read(buffer)) &gt;= 0) {
                  zos.write(buffer, 0, readBytesCount);
              }
              fis.close();
              sos.flush();
              zos.flush();
              zos.closeEntry();
          }
          zos.close();
      }
  
  
      protected void doPost(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
      public String getDirectory() {
          Properties prop;
          String home;
          String fileSeparator;
          String directoryName;
  
          prop = System.getProperties();
          home = prop.getProperty("user.dir").toString();
          fileSeparator = prop.getProperty("file.separator").toString();
          directoryName = "FileToDownload";
  
          return home + fileSeparator + directoryName;
      }
  
  }
  </code></pre>