/** * 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(); }
protected void writeDirEntry(ExtZipEntry entry) throws IOException { writeInt(CENSIG); // writeBytes( new byte[] { 0x50, 0x4b, 0x01, 0x02 } // ); // directory signature writeShort(ZIP_VERSION); // version made by writeFileInfo(entry); writeShort(0x00); // file comment length 2 bytes writeShort(0x00); // disk number start (unused) 2 bytes writeShort(0x00); // internal file attributes (unsued) 2 bytes writeInt(0x00); // external file attributes (unused) 4 bytes writeInt(entry.getOffset()); // relative offset of local header 4 bytes writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
protected void writeDirEntry(ExtZipEntry entry) throws IOException { writeInt(CENSIG); // writeBytes( new byte[] { 0x50, 0x4b, 0x01, 0x02 } // ); // directory signature writeShort(ZIP_VERSION); // version made by writeFileInfo(entry); writeShort(0x00); // file comment length 2 bytes writeShort(0x00); // disk number start (unused) 2 bytes writeShort(0x00); // internal file attributes (unsued) 2 bytes writeInt(0x00); // external file attributes (unused) 4 bytes writeInt(entry.getOffset()); // relative offset of local header 4 bytes writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
public void putNextEntry(ExtZipEntry entry) throws IOException { entries.add(entry); entry.setOffset(written); // file header signature writeInt(LOCSIG); writeFileInfo(entry); writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
public void putNextEntry(ExtZipEntry entry) throws IOException { entries.add(entry); entry.setOffset(written); // file header signature writeInt(LOCSIG); writeFileInfo(entry); writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
protected void writeFileInfo(ExtZipEntry entry) throws IOException { writeShort(ZIP_VERSION); // version needed to extract // general purpose bit flag - 0x0001 indicates encryption 2 bytes writeShort(entry.getFlag()); writeShort(entry.getPrimaryCompressionMethod()); // primary compression // method - // 0x63==encryption writeInt(entry.getDosTime()); // 2 bytes last mod file time + 2 bytes // last mod file date writeInt(entry.getCrc()); // 28 bytes is the encryption overhead (caused by 256-bit AES key) // 2 bytes pwVerification + 16 bytes SALT + 10 bytes AUTHENTICATION writeInt((int) entry.getCompressedSize()); // compressed size writeInt((int) entry.getSize()); // uncompressed size writeShort(entry.getName().length()); // file name length if (entry.getExtra() != null) { writeShort(entry.getExtra().length); // extra field length } else { writeShort(0); } }
protected void writeFileInfo(ExtZipEntry entry) throws IOException { writeShort(ZIP_VERSION); // version needed to extract // general purpose bit flag - 0x0001 indicates encryption 2 bytes writeShort(entry.getFlag()); writeShort(entry.getPrimaryCompressionMethod()); // primary compression // method - // 0x63==encryption writeInt(entry.getDosTime()); // 2 bytes last mod file time + 2 bytes // last mod file date writeInt(entry.getCrc()); // 28 bytes is the encryption overhead (caused by 256-bit AES key) // 2 bytes pwVerification + 16 bytes SALT + 10 bytes AUTHENTICATION writeInt((int) entry.getCompressedSize()); // compressed size writeInt((int) entry.getSize()); // uncompressed size writeShort(entry.getName().length()); // file name length if (entry.getExtra() != null) { writeShort(entry.getExtra().length); // extra field length } else { writeShort(0); } }