/** * Configures the stream to write prefix file data. * * @throws ZipException if other contents have already been written to the output stream */ public void startPrefixFile() throws ZipException { checkNotFinished(); if (!zipData.getEntries().isEmpty() || entry != null) { throw new ZipException("Cannot add a prefix file after the zip contents have been started."); } writingPrefix = true; }
/** * 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; }
/** * Sets the ZIP file comment. * * @param comment the ZIP file comment * @throws ZipException if the comment is longer than 0xffff bytes */ public void setComment(String comment) throws ZipException { zipData.setComment(comment); }
/** * Writes the ZIP file's central directory. * * @throws ZipException if a ZIP file error has occurred * @throws IOException if an I/O exception has occurred */ private void writeCentralDirectory() throws IOException { zipData.setCentralDirectoryOffset(stream.getCount()); CentralDirectory.write(zipData, allowZip64, stream); }