final long cdEntries = entries.size(); final long cdOffset = this.cdOffset; final long cdSize = dos.size() - cdOffset; final boolean cdEntriesZip64 = cdEntries > UShort.MAX_VALUE || FORCE_ZIP64_EXT; final boolean cdSizeZip64 = cdSize > UInt .MAX_VALUE || FORCE_ZIP64_EXT; if (zip64) { final long zip64eocdOffset // relative offset of the zip64 end of central directory record = dos.size(); dos.writeInt(ZIP64_EOCDR_SIG); dos.writeLong(ZIP64_EOCDR_MIN_LEN - 12); dos.writeShort(63); dos.writeShort(46); // due to potential use of BZIP2 compression dos.writeInt(0); dos.writeInt(0); dos.writeLong(cdEntries); dos.writeLong(cdEntries); dos.writeLong(cdSize); dos.writeLong(cdOffset);
this.dos = out instanceof LEDataOutputStream ? (LEDataOutputStream) out : new LEDataOutputStream(out); this.delegate = new TeeOutputStream(dos, new MacOutputStream(mac)); dos.writeInt(SIGNATURE); dos.writeByte(ENVELOPE_TYPE_0); dos.writeByte(keyStrengthOrdinal); dos.writeShort(ITERATION_COUNT); dos.write(salt); this.start = dos.size(); assert ENVELOPE_TYPE_0_HEADER_LEN_WO_SALT + salt.length == start;
dos.writeInt(CFH_SIG); dos.writeShort((entry.getRawPlatform() << 8) | 63); dos.writeShort(entry.getRawVersionNeededToExtract()); dos.writeShort(entry.getGeneralPurposeBitFlags()); dos.writeShort(entry.getRawMethod()); dos.writeInt((int) entry.getRawTime()); dos.writeInt((int) entry.getRawCrc()); dos.writeInt((int) entry.getRawCompressedSize()); dos.writeInt((int) entry.getRawSize()); dos.writeShort(name.length); dos.writeShort(extra.length); dos.writeShort(comment.length); dos.writeShort(0); dos.writeShort(0); dos.writeInt((int) entry.getRawExternalAttributes());
@Override protected void finish() throws IOException { // Flush partial block to out, if any. super.finish(); final long trailer = dos.size(); final Mac mac = this.mac; assert mac.getMacSize() == klac.getMacSize(); final byte[] buf = new byte[mac.getMacSize()]; // MAC buffer int bufLength; // Compute and write the first half of the KLAC to the data envelope footer. // Please note that we will only use the first half of the // authentication code for security reasons. final long length = trailer - start; // message length klac(klac, length, buf); dos.write(buf, 0, buf.length / 2); // Compute and write the first half of the MAC to the data envelope footer. // Again, we will only use the first half of the // authentication code for security reasons. bufLength = mac.doFinal(buf, 0); assert bufLength == buf.length; dos.write(buf, 0, buf.length / 2); assert dos.size() - trailer == buf.length; } }
@Override protected void finish() throws IOException { // Flush partial block to out, if any. super.finish(); // Compute and write the first half of the MAC to the footer. final byte[] buf = mos.getMac(); dos.write(buf, 0, buf.length / 2); } }
/** * Returns the total number of (compressed) bytes this stream has written * to the underlying stream. */ public long length() { return this.dos.size(); }
@CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION") private static LEDataOutputStream newLEDataOutputStream( final @WillCloseWhenClosed OutputStream out, final @CheckForNull @WillNotClose RawZipFile<?> appendee) { if (null == out) throw new NullPointerException(); return null != appendee ? new AppendingLEDataOutputStream(out, appendee) : out instanceof LEDataOutputStream ? (LEDataOutputStream) out : new LEDataOutputStream(out); }
private void writePasswordVerifier(KeyParameter keyParam) throws IOException { dos.write( keyParam.getKey(), 2 * param.getKeyStrength().getBytes(), PWD_VERIFIER_BITS / 8); }
closeEntry(); final LEDataOutputStream dos = this.dos; this.cdOffset = dos.size(); final Iterator<E> i = this.entries.values().iterator(); while (i.hasNext())
dos.write(salt); writePasswordVerifier(keyParam);