This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f1953d  Add EOS constant that represent  the end of the stream
     new c7a48d0  Merge pull request #132 from 
arturobernalg/feature/end_of_stream
7f1953d is described below

commit 7f1953dba7e630ba5e18dc569d786c2a95009e18
Author: Arturo Bernal <[email protected]>
AuthorDate: Wed Feb 17 20:51:44 2021 +0100

    Add EOS constant that represent  the end of the stream
---
 .../commons/crypto/stream/CryptoInputStream.java      | 19 +++++++++++++------
 .../commons/crypto/stream/input/StreamInput.java      | 12 +++++++-----
 2 files changed, 20 insertions(+), 11 deletions(-)

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 a7aa93d..27afbf9 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -102,6 +102,13 @@ public class CryptoInputStream extends InputStream 
implements
     private static final int MIN_BUFFER_SIZE = 512;
 
     /**
+     * The index value when the end of the stream has been reached {@code -1}.
+     *
+     * @since 1.1
+     */
+    public static final int EOS = -1;
+
+    /**
      * Constructs a {@link CryptoInputStream}.
      *
      * @param transformation the name of the transformation, e.g.,
@@ -213,7 +220,7 @@ public class CryptoInputStream extends InputStream 
implements
      * Overrides the {@link java.io.InputStream#read()}. Reads the next byte of
      * data from the input stream.
      *
-     * @return the next byte of data, or {@code -1} if the end of the
+     * @return the next byte of data, or {@code EOS (-1)} if the end of the
      *         stream is reached.
      * @throws IOException if an I/O error occurs.
      */
@@ -223,7 +230,7 @@ public class CryptoInputStream extends InputStream 
implements
         while ((n = read(oneByteBuf, 0, 1)) == 0) { //NOPMD
             /* no op */
         }
-        return (n == -1) ? -1 : oneByteBuf[0] & 0xff;
+        return (n == EOS) ? EOS : oneByteBuf[0] & 0xff;
     }
 
     /**
@@ -380,7 +387,7 @@ public class CryptoInputStream extends InputStream 
implements
      * sequence of bytes from this channel into the given buffer.
      *
      * @param dst The buffer into which bytes are to be transferred.
-     * @return The number of bytes read, possibly zero, or {@code -1} if the
+     * @return The number of bytes read, possibly zero, or {@code EOS (-1)} if 
the
      *         channel has reached end-of-stream.
      * @throws IOException if an I/O error occurs.
      */
@@ -397,7 +404,7 @@ public class CryptoInputStream extends InputStream 
implements
             }
 
             if (nd < 0) {
-                return -1;
+                return EOS;
             }
         }
 
@@ -485,7 +492,7 @@ public class CryptoInputStream extends InputStream 
implements
      */
     protected int decryptMore() throws IOException {
         if (finalDone) {
-            return -1;
+            return EOS;
         }
 
         final int n = input.read(inBuffer);
@@ -500,7 +507,7 @@ public class CryptoInputStream extends InputStream 
implements
             }
 
             // End of the stream
-            return -1;
+            return EOS;
         } else if (n == 0) {
             // No data is read, but the stream is not end yet
             return 0;
diff --git 
a/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java 
b/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
index 47af994..76c1634 100644
--- a/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
@@ -21,7 +21,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
 
-/**
+import static org.apache.commons.crypto.stream.CryptoInputStream.EOS;
+
+ /**
  * The StreamInput class takes a {@code InputStream} object and wraps it as
  * {@code Input} object acceptable by {@code CryptoInputStream}.
  */
@@ -50,7 +52,7 @@ public class StreamInput implements Input {
      * @param dst The buffer into which bytes are to be transferred.
      *
      * @return the total number of bytes read into the buffer, or
-     *         {@code -1} if there is no more data because the end of the
+     *         {@code EOS (-1)} if there is no more data because the end of the
      *         stream has been reached.
      * @throws IOException if an I/O error occurs.
      */
@@ -60,9 +62,9 @@ public class StreamInput implements Input {
         int read = 0;
         while (remaining > 0) {
             final int n = in.read(buf, 0, Math.min(remaining, bufferSize));
-            if (n == -1) {
+            if (n == EOS) {
                 if (read == 0) {
-                    read = -1;
+                    read = EOS;
                 }
                 break;
             } else if (n > 0) {
@@ -119,7 +121,7 @@ public class StreamInput implements Input {
      * @param offset the start offset in array buffer.
      * @param length the maximum number of bytes to read.
      * @return the total number of bytes read into the buffer, or
-     *         {@code -1} if there is no more data because the end of the
+     *         {@code EOS (-1)} if there is no more data because the end of the
      *         stream has been reached.
      * @throws IOException if an I/O error occurs.
      */

Reply via email to