commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject commons-crypto git commit: CRYPTO-127: CryptoInputStream#read should handle non-block case
Date Mon, 14 Nov 2016 08:18:09 GMT
Repository: commons-crypto
Updated Branches:
  refs/heads/master 3adc20723 -> a760177b6


CRYPTO-127: CryptoInputStream#read should handle non-block case

Closes #72 from kexianda/inputstream


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/a760177b
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/a760177b
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/a760177b

Branch: refs/heads/master
Commit: a760177b6d1b95bef512902c0b987ace614ab359
Parents: 3adc207
Author: Xianda Ke <xianda.ke@intel.com>
Authored: Mon Oct 24 11:22:21 2016 +0800
Committer: Sun Dapeng <sdp@apache.org>
Committed: Mon Nov 14 16:09:05 2016 +0800

----------------------------------------------------------------------
 .../crypto/stream/CryptoInputStream.java        | 25 ++++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/a760177b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
index cd1e639..c3441fd 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -255,8 +255,12 @@ public class CryptoInputStream extends InputStream implements
             return n;
         }
         // No data in the out buffer, try read new data and decrypt it
-        int nd = decryptMore();
-        if (nd <= 0) {
+        // we loop for new data
+        int nd = 0;
+        while (nd == 0) {
+            nd = decryptMore();
+        }
+        if (nd < 0) {
             return nd;
         }
 
@@ -297,7 +301,11 @@ public class CryptoInputStream extends InputStream implements
             remaining -= outBuffer.remaining();
             outBuffer.clear();
 
-            nd = decryptMore();
+            // we loop for new data
+            nd = 0;
+            while (nd == 0) {
+                nd = decryptMore();
+            }
             if (nd < 0) {
                 break;
             }
@@ -402,7 +410,12 @@ public class CryptoInputStream extends InputStream implements
         int remaining = outBuffer.remaining();
         if (remaining <= 0) {
             // Decrypt more data
-            int nd = decryptMore();
+            // we loop for new data
+            int nd = 0;
+            while (nd == 0) {
+                nd = decryptMore();
+            }
+
             if (nd < 0) {
                 return -1;
             }
@@ -487,7 +500,9 @@ public class CryptoInputStream extends InputStream implements
      * will be put in the output buffer. If the end of the under stream reached,
      * we will do final of the cipher to finish all the decrypting of data.
      *
-     * @return The number of decrypted data. -1 if end of the decrypted stream.
+     * @return The number of decrypted data.
+     *           return -1 (if end of the decrypted stream)
+     *           return 0 (no data now, but could have more later)
      * @throws IOException if an I/O error occurs.
      */
     protected int decryptMore() throws IOException {


Mime
View raw message