Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BAA39200BBF for ; Mon, 14 Nov 2016 09:18:11 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B942A160B06; Mon, 14 Nov 2016 08:18:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0EA9E160B05 for ; Mon, 14 Nov 2016 09:18:10 +0100 (CET) Received: (qmail 10058 invoked by uid 500); 14 Nov 2016 08:18:10 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 10049 invoked by uid 99); 14 Nov 2016 08:18:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2016 08:18:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CC145DFFAB; Mon, 14 Nov 2016 08:18:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sdp@apache.org To: commits@commons.apache.org Message-Id: <69521b6d5b91449a97d2c2944d8d601f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: commons-crypto git commit: CRYPTO-127: CryptoInputStream#read should handle non-block case Date: Mon, 14 Nov 2016 08:18:09 +0000 (UTC) archived-at: Mon, 14 Nov 2016 08:18:11 -0000 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 Authored: Mon Oct 24 11:22:21 2016 +0800 Committer: Sun Dapeng 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 {