title: Java - Zip output stream dynamic buffer size
body: <p>I'm working on application that takes files from one zip and put them in the other, its fine with files but if there is a dir in the source zip it fail with the following exception:</p>
  
  <pre><code>Exception in thread "main" java.util.zip.ZipException: invalid entry size (expected 1374 but got 1024 bytes)
  </code></pre>
  
  <p>I'm using the following code:</p>
  
  <pre><code>public static void ZipExtractToZip(File inZip, File outZip) throws IOException
  {
      ZipInputStream zis = new ZipInputStream(new FileInputStream(inZip));
      ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outZip)));
      byte[] buffer = new byte[1024];
  
      for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) 
      {
          zos.putNextEntry(ze);
          for (int read = zis.read(buffer); read != -1; read = zis.read(buffer)) {
              zos.write(buffer, 0, read);
          }
          zos.closeEntry();
      }
  
      zos.close();
      zis.close();
  }
  </code></pre>
  
  <p>I have tried different buffer sizes but that doesn't help, I need a way to get a dynamic buffer size.
  Examples and links are welcome.</p>
  
  <p><strong>EDIT:</strong> I changed the code to make it usable</p>
  
  <ul>
  <li>Liam, <a href="http://hachisoftware.com" rel="nofollow">Hachi Software</a> CEO</li>
  </ul>