title: What is the buffer size to create a .zip archive using Java?
body: <p>I use this code to create a .zip with a list of files:</p>
  
  <pre><code>ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
  
  for (int i=0;i&lt;srcFiles.length;i++){
      String fileName=srcFiles[i].getName();
      ZipEntry zipEntry = new ZipEntry(fileName);
      zos.putNextEntry(zipEntry);
      InputStream fis = new FileInputStream(srcFiles[i]);
      int read;
      for(byte[] buffer=new byte[1024];(read=fis.read(buffer))&gt;0;){
          zos.write(buffer,0,read);
      }
      fis.close();
      zos.closeEntry();
  }
  zos.close();
  </code></pre>
  
  <p>I don't know how the zip algorithm and the ZipOutputStream works, if it writes something before I read and send to 'zos' all of the data, the result file can be different in size of bytes than if I choose another buffer size. </p>
  
  <p>in other words I don't know if the algorithm is like:</p>
  
  <p>READ DATA-->PROCESS DATA-->CREATE .ZIP</p>
  
  <p>or</p>
  
  <p>READ CHUNK OF DATA-->PROCESS CHUNK OF DATA-->WRITE CHUNK IN .ZIP-->|
  ^-----------------------------------------------------------------------------------------------------------------------------</p>
  
  <p>If this is the case, what buffer size is the best?</p>
  
  <p>Update:</p>
  
  <p>I have tested this code, changing the buffer size from 1024 to 64, and zipping the same files: with 1024 bytes the 80 KB result file was 3 bytes smaller than with 64 bytes buffer. Which is the best buffer size to produce the smallest .zip in the fatest time?</p>