< prev index next >

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

Print this page

        

@@ -49,18 +49,25 @@
      * Input buffer for decompression.
      */
     protected byte[] buf;
 
     /**
+     * Original input buffer.
+     */
+    protected byte[] originBuf;
+
+    /**
      * Length of input buffer.
      */
     protected int len;
 
     private boolean closed = false;
     // this flag is set to true after EOF has reached
     private boolean reachEOF = false;
 
+    private ZipCryption zipCryption;
+
     /**
      * Check to make sure that this stream has not been closed
      */
     private void ensureOpen() throws IOException {
         if (closed) {

@@ -84,10 +91,11 @@
         } else if (size <= 0) {
             throw new IllegalArgumentException("buffer size <= 0");
         }
         this.inf = inf;
         buf = new byte[size];
+        originBuf = new byte[size];
     }
 
     /**
      * Creates a new input stream with the specified decompressor and a
      * default buffer size.

@@ -237,10 +245,16 @@
         ensureOpen();
         len = in.read(buf, 0, buf.length);
         if (len == -1) {
             throw new EOFException("Unexpected end of ZLIB input stream");
         }
+
+        if (zipCryption != null) {
+            System.arraycopy(buf, 0, originBuf, 0, len);
+            zipCryption.decryptBytes(buf, 0, len);
+        }
+
         inf.setInput(buf, 0, len);
     }
 
     /**
      * Tests if this input stream supports the <code>mark</code> and

@@ -283,6 +297,17 @@
      * @see     java.io.IOException
      */
     public synchronized void reset() throws IOException {
         throw new IOException("mark/reset not supported");
     }
+
+    /**
+     * Set ZIP encryption/decryption engine to this inflater.
+     *
+     * @param zipCryption ZIP encrypt/decrypt engine. zip decryption will not
+     * work if this value set to null.
+     * @since 1.9
+     */
+    public void setZipCryption(ZipCryption zipCryption) {
+        this.zipCryption = zipCryption;
+    }
 }
< prev index next >