--- old/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java 2015-12-16 23:41:18.556242077 +0900 +++ new/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java 2015-12-16 23:41:18.350243315 +0900 @@ -58,6 +58,8 @@ private final boolean syncFlush; + private ZipCryption zipCryption; + /** * Creates a new output stream with the specified compressor, * buffer size and flush mode. @@ -250,6 +252,11 @@ 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); } } @@ -274,6 +281,11 @@ 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; @@ -281,4 +293,16 @@ } 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; + } + }