You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2008/07/01 06:39:02 UTC

svn commit: r672993 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java

Author: bayard
Date: Mon Jun 30 21:39:01 2008
New Revision: 672993

URL: http://svn.apache.org/viewvc?rev=672993&view=rev
Log:
Applying Sebb's patch from CODEC-71, improving the memory consumption of isArrayByteBase64(). I've also deprecated the discardWhitespace method as nothing uses it now

Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java?rev=672993&r1=672992&r2=672993&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java Mon Jun 30 21:39:01 2008
@@ -476,15 +476,8 @@
      *         empty; false, otherwise
      */
     public static boolean isArrayByteBase64(byte[] arrayOctet) {
-
-        arrayOctet = discardWhitespace(arrayOctet);
-
-        int length = arrayOctet.length;
-        if (length == 0) {
-             return true;
-        }
-        for (int i = 0; i < length; i++) {
-            if (!isBase64(arrayOctet[i])) {
+        for (int i = 0; i < arrayOctet.length; i++) {
+            if (!isBase64(arrayOctet[i]) && !isWhiteSpace(arrayOctet[i])) {
                 return false;
             }
         }
@@ -630,6 +623,7 @@
      * @param data
      *            The base-64 encoded data to discard the whitespace from.
      * @return The data, less whitespace (see RFC 2045).
+     * @deprecated This method is no longer needed
      */
     static byte[] discardWhitespace(byte[] data) {
         byte groomedData[] = new byte[data.length];
@@ -654,6 +648,25 @@
         return packedData;
     }
 
+
+    /**
+     * Check if a byte value is whitespace or not.
+     * 
+     * @param byteToCheck the byte to check
+     * @return true if byte is whitespace, false otherwise
+     */
+    private static boolean isWhiteSpace(byte byteToCheck){
+        switch (byteToCheck) {
+        case ' ' :
+        case '\n' :
+        case '\r' :
+        case '\t' :
+            return true;
+        default :
+            return false;
+        }
+    }
+
     /**
      * Discards any characters outside of the base64 alphabet, per the requirements on page 25 of RFC 2045 - "Any
      * characters outside of the base64 alphabet are to be ignored in base64 encoded data."