You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2011/01/25 02:53:48 UTC

svn commit: r1063100 - in /commons/proper/codec/trunk/src: java/org/apache/commons/codec/binary/Base64.java test/org/apache/commons/codec/binary/Base64Test.java

Author: ggregory
Date: Tue Jan 25 01:53:47 2011
New Revision: 1063100

URL: http://svn.apache.org/viewvc?rev=1063100&view=rev
Log:
[CODEC-110] Add a String version of Base64.isArrayByteBase64(). https://issues.apache.org/jira/browse/CODEC-110

Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Base64.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.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=1063100&r1=1063099&r2=1063100&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 Tue Jan 25 01:53:47 2011
@@ -590,6 +590,20 @@ public class Base64 implements BinaryEnc
     }
 
     /**
+     * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
+     * method treats whitespace as valid.
+     * 
+     * @param base64
+     *            String to test
+     * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if
+     *         the String is empty; <code>false</code>, otherwise
+     *  @since 1.5
+     */
+    public static boolean isBase64(String base64) {
+        return isArrayByteBase64(StringUtils.getBytesUtf8(base64));
+    }
+
+    /**
      * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
      * method treats whitespace as valid.
      * 
@@ -606,19 +620,6 @@ public class Base64 implements BinaryEnc
         }
         return true;
     }
-
-    /**
-     * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
-     * method treats whitespace as valid.
-     * 
-     * @param base64
-     *            String of (presumably) base64 characters to test
-     * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if
-     *         the String is empty; false, otherwise
-     */
-    public static boolean isStringBase64(String base64) {
-        return isArrayByteBase64(StringUtils.getBytesUtf8(base64));
-    }
     
     /**
      * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java?rev=1063100&r1=1063099&r2=1063100&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java Tue Jan 25 01:53:47 2011
@@ -65,15 +65,15 @@ public class Base64Test extends TestCase
         String invalidString = validString + ((char)0); // append null character
         
         try {
-            Base64.isStringBase64(nullString);
+            Base64.isBase64(nullString);
             fail("Base64.isStringBase64() should not be null-safe.");
         } catch (NullPointerException npe) {
             assertNotNull("Base64.isStringBase64() should not be null-safe.", npe);
         }
         
-        assertTrue("Base64.isStringBase64(empty-string) is true", Base64.isStringBase64(emptyString));
-        assertTrue("Base64.isStringBase64(valid-string) is true", Base64.isStringBase64(validString));        
-        assertFalse("Base64.isStringBase64(invalid-string) is false", Base64.isStringBase64(invalidString));        
+        assertTrue("Base64.isStringBase64(empty-string) is true", Base64.isBase64(emptyString));
+        assertTrue("Base64.isStringBase64(valid-string) is true", Base64.isBase64(validString));        
+        assertFalse("Base64.isStringBase64(invalid-string) is false", Base64.isBase64(invalidString));        
     }
     
     /**