title: How to create a multipart zip file and read it back?
body: <p>How would I properly <strong>zip</strong> bytes to a <code>ByteArrayOutputStream</code> and then read that using a <code>ByteArrayInputStream</code>? I have the following method:</p>
  
  <pre><code>private byte[] getZippedBytes(final String fileName, final byte[] input) throws Exception {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ZipOutputStream zipOut = new ZipOutputStream(bos);
      ZipEntry entry = new ZipEntry(fileName);
      entry.setSize(input.length);
      zipOut.putNextEntry(entry);
      zipOut.write(input, 0, input.length);
      zipOut.closeEntry();
      zipOut.close();
  
      //Turn right around and unzip what we just zipped
      ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
  
      while((entry = zipIn.getNextEntry()) != null) {
          assert entry.getSize() &gt;= 0;
      }
  
      return bos.toByteArray();
  }
  </code></pre>
  
  <p>When I execute this code, the assertion at the bottom fails because <code>entry.size</code> is <code>-1</code>. I don't understand why the extracted entity doesn't match the entity that was zipped.</p>