Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm leery of <strong>aperkins</strong> solution (since deleted), but I know why it worked. The line (which has since been corrected in his answer)</p> <pre><code>zipOut.setLevel(ZipOutputStream.STORED); // accidentally right </code></pre> <p>was using the static value <code>ZipOutputStream.STORED</code>, which coincidentally equals <code>0</code>. So what that line is doing is setting the <em>level</em> used by the default DEFLATED method to zero compression (this is obviously what you want to do, but happened to only work by luck). So to get what you want explicitly and safely, use this instead:</p> <pre><code>zipOut.setMethod(ZipOutputStream.DEFLATED); // this line optional zipOut.setLevel(0); </code></pre> <p>or</p> <pre><code>zipOut.setLevel(Deflater.NO_COMPRESSION); </code></pre> <p>If you use</p> <pre><code>zipOut.setMethod(ZipOutputStream.STORED); zipOut.setLevel(Deflater.NO_COMPRESSION); </code></pre> <p>you'll probably get the Exception that Keya noted in the original question. I believe <strong>Christian Schlichtherle</strong> is right; you are getting the Exceptions because you are not setting the CRC in the entry. The repercussions of that is that to use the STORED method, you have to read the entire entry file first, or find some other way to set the size, compressed size (must be equal) and the CRC before you call <code>zipOut.putNextEntry()</code>. Otherwise, you'll run into more exceptions if you overrun the size attribute by writing too many bytes to the output stream. It appears that the ZIP specs say that if you are writing STORED data then it has to write the header [which includes the CRC-32 and length] "up front" before the data itself, hence the java API requiring these be set before it can start, since it basically only supports streaming out to the final zip file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload