File tree Expand file tree Collapse file tree
java/org/apache/commons/codec/binary
test/org/apache/commons/codec/binary Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -589,6 +589,20 @@ public static boolean isBase64(byte octet) {
589589 return octet == PAD || (octet >= 0 && octet < DECODE_TABLE .length && DECODE_TABLE [octet ] != -1 );
590590 }
591591
592+ /**
593+ * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
594+ * method treats whitespace as valid.
595+ *
596+ * @param base64
597+ * String to test
598+ * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if
599+ * the String is empty; <code>false</code>, otherwise
600+ * @since 1.5
601+ */
602+ public static boolean isBase64 (String base64 ) {
603+ return isArrayByteBase64 (StringUtils .getBytesUtf8 (base64 ));
604+ }
605+
592606 /**
593607 * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
594608 * method treats whitespace as valid.
@@ -606,19 +620,6 @@ public static boolean isArrayByteBase64(byte[] arrayOctet) {
606620 }
607621 return true ;
608622 }
609-
610- /**
611- * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
612- * method treats whitespace as valid.
613- *
614- * @param base64
615- * String of (presumably) base64 characters to test
616- * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if
617- * the String is empty; false, otherwise
618- */
619- public static boolean isStringBase64 (String base64 ) {
620- return isArrayByteBase64 (StringUtils .getBytesUtf8 (base64 ));
621- }
622623
623624 /**
624625 * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
Original file line number Diff line number Diff line change @@ -65,15 +65,15 @@ public void testIsStringBase64() {
6565 String invalidString = validString + ((char )0 ); // append null character
6666
6767 try {
68- Base64 .isStringBase64 (nullString );
68+ Base64 .isBase64 (nullString );
6969 fail ("Base64.isStringBase64() should not be null-safe." );
7070 } catch (NullPointerException npe ) {
7171 assertNotNull ("Base64.isStringBase64() should not be null-safe." , npe );
7272 }
7373
74- assertTrue ("Base64.isStringBase64(empty-string) is true" , Base64 .isStringBase64 (emptyString ));
75- assertTrue ("Base64.isStringBase64(valid-string) is true" , Base64 .isStringBase64 (validString ));
76- assertFalse ("Base64.isStringBase64(invalid-string) is false" , Base64 .isStringBase64 (invalidString ));
74+ assertTrue ("Base64.isStringBase64(empty-string) is true" , Base64 .isBase64 (emptyString ));
75+ assertTrue ("Base64.isStringBase64(valid-string) is true" , Base64 .isBase64 (validString ));
76+ assertFalse ("Base64.isStringBase64(invalid-string) is false" , Base64 .isBase64 (invalidString ));
7777 }
7878
7979 /**
You can’t perform that action at this time.
0 commit comments