Example #1
0
 /**
  * Closes the current ZIP entry and positions the stream for writing the next entry. Checks that
  * the amount of data written matches the compressed size indicated by the ZipEntry.
  *
  * @throws ZipException if a ZIP file error has occurred
  * @throws IOException if an I/O exception has occurred
  */
 private void finishEntry() throws IOException {
   if (entry.getCompressedSize() != bytesWritten) {
     throw new ZipException(
         String.format(
             "Number of bytes written for the entry %s (%d) does not"
                 + " match the reported compressed size (%d).",
             entry.getName(), bytesWritten, entry.getCompressedSize()));
   }
   zipData.addEntry(entry);
   entry = null;
 }
Example #2
0
 /**
  * Writes the local file header for the ZIP entry and positions the stream to the start of the
  * entry data.
  *
  * @param e the ZIP entry for which to write the local file header
  * @throws ZipException if a ZIP file error has occurred
  * @throws IOException if an I/O exception has occurred
  */
 private void startEntry(ZipFileEntry e) throws IOException {
   if (e.getTime() == -1) {
     throw new IllegalArgumentException("Zip entry last modified time must be set");
   }
   if (e.getCrc() == -1) {
     throw new IllegalArgumentException("Zip entry CRC-32 must be set");
   }
   if (e.getSize() == -1) {
     throw new IllegalArgumentException("Zip entry uncompressed size must be set");
   }
   if (e.getCompressedSize() == -1) {
     throw new IllegalArgumentException("Zip entry compressed size must be set");
   }
   bytesWritten = 0;
   entry = e;
   entry.setFlag(Flag.DATA_DESCRIPTOR, false);
   entry.setLocalHeaderOffset(stream.getCount());
   stream.write(LocalFileHeader.create(entry, zipData, allowZip64));
 }