< prev index next >

src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java

Print this page

        

*** 56,65 **** --- 56,67 ---- private boolean closed = false; private final boolean syncFlush; + private ZipCryption zipCryption; + /** * Creates a new output stream with the specified compressor, * buffer size and flush mode. * @param out the output stream
*** 248,257 **** --- 250,264 ---- * @throws IOException if an I/O error has occurred */ protected void deflate() throws IOException { int len = def.deflate(buf, 0, buf.length); if (len > 0) { + + if (zipCryption != null) { + zipCryption.encryptBytes(buf, 0, len); + } + out.write(buf, 0, len); } } /**
*** 272,284 **** --- 279,308 ---- public void flush() throws IOException { if (syncFlush && !def.finished()) { int len = 0; while ((len = def.deflate(buf, 0, buf.length, Deflater.SYNC_FLUSH)) > 0) { + + if (zipCryption != null) { + zipCryption.encryptBytes(buf, 0, len); + } + out.write(buf, 0, len); if (len < buf.length) break; } } out.flush(); } + + /** + * Set ZIP encryption/decryption engine to this deflater. + * + * @param zipCryption ZIP encrypt/decrypt engine. zip encryption will not + * work if this value set to null. + * @since 1.9 + */ + public void setZipCryption(ZipCryption zipCryption) { + this.zipCryption = zipCryption; + } + }
< prev index next >