Repository: commons-crypto
Updated Branches:
  refs/heads/master 984ee1024 -> 6a0817217


CRYPTO-87 Reduce util package API footprint

getBufferSize

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

Branch: refs/heads/master
Commit: 6a081721710309f920624d0843d912f6a2396d47
Parents: 984ee10
Author: Sebb <s...@apache.org>
Authored: Sat Jun 25 13:30:28 2016 +0100
Committer: Sebb <s...@apache.org>
Committed: Sat Jun 25 13:30:28 2016 +0100

----------------------------------------------------------------------
 .../crypto/stream/CTRCryptoInputStream.java     |  8 +++---
 .../crypto/stream/CTRCryptoOutputStream.java    |  8 +++---
 .../crypto/stream/CryptoInputStream.java        | 27 +++++++++++++++++---
 .../crypto/stream/CryptoOutputStream.java       |  6 ++---
 .../stream/PositionedCryptoInputStream.java     |  2 +-
 .../org/apache/commons/crypto/utils/Utils.java  | 20 ---------------
 6 files changed, 36 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java 
b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
index 84fc05e..c7fbf32 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
@@ -168,8 +168,8 @@ public class CTRCryptoInputStream extends CryptoInputStream 
{
     public CTRCryptoInputStream(Properties props, InputStream in, byte[] key,
             byte[] iv, long streamOffset) throws IOException {
         this(in, Utils.getCipherInstance(
-                "AES/CTR/NoPadding", props), Utils
-                .getBufferSize(props), key, iv, streamOffset);
+                "AES/CTR/NoPadding", props),
+                CryptoInputStream.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**
@@ -186,8 +186,8 @@ public class CTRCryptoInputStream extends CryptoInputStream 
{
     public CTRCryptoInputStream(Properties props, ReadableByteChannel in,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(in, Utils.getCipherInstance(
-                "AES/CTR/NoPadding", props), Utils
-                .getBufferSize(props), key, iv, streamOffset);
+                "AES/CTR/NoPadding", props),
+                CryptoInputStream.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java 
b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
index 0025a7a..6c54715 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
@@ -168,8 +168,8 @@ public class CTRCryptoOutputStream extends 
CryptoOutputStream {
     public CTRCryptoOutputStream(Properties props, OutputStream out,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(out, Utils.getCipherInstance(
-                "AES/CTR/NoPadding", props), Utils
-                .getBufferSize(props), key, iv, streamOffset);
+                "AES/CTR/NoPadding", props),
+                CryptoInputStream.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**
@@ -186,8 +186,8 @@ public class CTRCryptoOutputStream extends 
CryptoOutputStream {
     public CTRCryptoOutputStream(Properties props, WritableByteChannel out,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(out, Utils.getCipherInstance(
-                "AES/CTR/NoPadding", props), Utils
-                .getBufferSize(props), key, iv, streamOffset);
+                "AES/CTR/NoPadding", props),
+                CryptoInputStream.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/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 c4a6935..f50fe12 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -33,6 +33,7 @@ import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 
 import org.apache.commons.crypto.cipher.CryptoCipher;
+import org.apache.commons.crypto.conf.ConfigurationKeys;
 import org.apache.commons.crypto.stream.input.ChannelInput;
 import org.apache.commons.crypto.stream.input.Input;
 import org.apache.commons.crypto.stream.input.StreamInput;
@@ -103,8 +104,8 @@ public class CryptoInputStream extends InputStream 
implements
     public CryptoInputStream(String transformation,
             Properties props, InputStream in, Key key,
             AlgorithmParameterSpec params) throws IOException {
-        this(in, Utils.getCipherInstance(transformation, props), Utils
-                .getBufferSize(props), key, params);
+        this(in, Utils.getCipherInstance(transformation, props),
+                CryptoInputStream.getBufferSize(props), key, params);
     }
 
     /**
@@ -124,7 +125,7 @@ public class CryptoInputStream extends InputStream 
implements
     public CryptoInputStream(String transformation,
             Properties props, ReadableByteChannel in, Key key,
             AlgorithmParameterSpec params) throws IOException {
-        this(in, Utils.getCipherInstance(transformation, props), Utils
+        this(in, Utils.getCipherInstance(transformation, props), 
CryptoInputStream
                 .getBufferSize(props), key, params);
     }
 
@@ -571,6 +572,26 @@ public class CryptoInputStream extends InputStream 
implements
     }
 
     /**
+     * Reads crypto buffer size.
+     *
+     * @param props The <code>Properties</code> class represents a set of
+     *        properties.
+     * @return the buffer size.
+     * */
+    static int getBufferSize(Properties props) {
+        String bufferSizeStr = props
+                .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
+        if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
+            bufferSizeStr = System
+                    .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
+        }
+        if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
+            return ConfigurationKeys.STREAM_BUFFER_SIZE_DEFAULT;
+        }
+        return Integer.parseInt(bufferSizeStr);
+    }
+
+    /**
      * Checks whether the cipher is supported streaming.
      *
      * @param cipher the {@link CryptoCipher} instance.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java 
b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
index f89b7df..e23e548 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
@@ -97,8 +97,8 @@ public class CryptoOutputStream extends OutputStream 
implements
     public CryptoOutputStream(String transformation,
             Properties props, OutputStream out, Key key,
             AlgorithmParameterSpec params) throws IOException {
-        this(out, Utils.getCipherInstance(transformation, props), Utils
-                .getBufferSize(props), key, params);
+        this(out, Utils.getCipherInstance(transformation, props),
+                CryptoInputStream.getBufferSize(props), key, params);
 
     }
 
@@ -119,7 +119,7 @@ public class CryptoOutputStream extends OutputStream 
implements
     public CryptoOutputStream(String transformation,
             Properties props, WritableByteChannel out, Key key,
             AlgorithmParameterSpec params) throws IOException {
-        this(out, Utils.getCipherInstance(transformation, props), Utils
+        this(out, Utils.getCipherInstance(transformation, props), 
CryptoInputStream
                 .getBufferSize(props), key, params);
 
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
 
b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
index da565d1..939c1c9 100644
--- 
a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
+++ 
b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
@@ -73,7 +73,7 @@ public class PositionedCryptoInputStream extends 
CTRCryptoInputStream {
     public PositionedCryptoInputStream(Properties props, Input in, byte[] key,
             byte[] iv, long streamOffset) throws IOException {
         this(props, in, Utils.getCipherInstance("AES/CTR/NoPadding", props),
-                Utils.getBufferSize(props), key, iv, streamOffset);
+                CryptoInputStream.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6a081721/src/main/java/org/apache/commons/crypto/utils/Utils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java 
b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index 3a113f3..1aaf14d 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -116,26 +116,6 @@ public final class Utils {
     }
 
     /**
-     * Reads crypto buffer size.
-     *
-     * @param props The <code>Properties</code> class represents a set of
-     *        properties.
-     * @return the buffer size.
-     * */
-    public static int getBufferSize(Properties props) {
-        String bufferSizeStr = props
-                .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
-        if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
-            bufferSizeStr = System
-                    .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
-        }
-        if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
-            return ConfigurationKeys.STREAM_BUFFER_SIZE_DEFAULT;
-        }
-        return Integer.parseInt(bufferSizeStr);
-    }
-
-    /**
      * <p>
      * This method is only for Counter (CTR) mode. Generally the CryptoCipher
      * calculates the IV and maintain encryption context internally.For example

Reply via email to