commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r672993 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
Date Tue, 01 Jul 2008 04:39:02 GMT
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."



Mime
View raw message