/** * Finishes writing the contents of the ZIP output stream. */ public void finish() throws IOException { int dirOffset = written; // central directory (at end of zip file) // starts here int startOfCentralDirectory = written; Iterator<ExtZipEntry> it = entries.iterator(); while (it.hasNext()) { ExtZipEntry entry = it.next(); writeDirEntry(entry); } int centralDirectorySize = written - startOfCentralDirectory; writeInt(ENDSIG); // end of central dir signature 4 bytes writeShort(0x00); // number of this disk 2 bytes writeShort(0x00); // number of the disk with the start of the central directory 2 bytes writeShort(entries.size()); // total number of entries in central directory on this disk 2 bytes writeShort(entries.size()); // total number of entries in the central directory 2 bytes writeInt(centralDirectorySize); // size of the central directory 4 bytes writeInt(dirOffset); // offset of start of central dir, with respect to starting disk 4 bytes byte[] commentBytes = this.comment!=null ? this.comment.getBytes() : new byte[0]; writeShort(commentBytes.length); // .ZIP file comment length 2 bytes if( commentBytes.length>0 ) { writeBytes(commentBytes); } out.close(); }
/** * Finishes writing the contents of the ZIP output stream. */ public void finish() throws IOException { int dirOffset = written; // central directory (at end of zip file) // starts here int startOfCentralDirectory = written; Iterator<ExtZipEntry> it = entries.iterator(); while (it.hasNext()) { ExtZipEntry entry = it.next(); writeDirEntry(entry); } int centralDirectorySize = written - startOfCentralDirectory; writeInt(ENDSIG); // end of central dir signature 4 bytes writeShort(0x00); // number of this disk 2 bytes writeShort(0x00); // number of the disk with the start of the central directory 2 bytes writeShort(entries.size()); // total number of entries in central directory on this disk 2 bytes writeShort(entries.size()); // total number of entries in the central directory 2 bytes writeInt(centralDirectorySize); // size of the central directory 4 bytes writeInt(dirOffset); // offset of start of central dir, with respect to starting disk 4 bytes byte[] commentBytes = this.comment!=null ? this.comment.getBytes() : new byte[0]; writeShort(commentBytes.length); // .ZIP file comment length 2 bytes if( commentBytes.length>0 ) { writeBytes(commentBytes); } out.close(); }