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 3131 * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
3232 * @author Apache Software Foundation
3333 * @since 1.0-dev
34- * @version $Id: Base64.java,v 1.22 2004/10/30 00:18:57 ggregory Exp $
34+ * @version $Id: Base64.java,v 1.23 2004/11/24 19:23:25 ggregory Exp $
3535 */
3636public class Base64 implements BinaryEncoder , BinaryDecoder {
3737
@@ -153,10 +153,16 @@ public class Base64 implements BinaryEncoder, BinaryDecoder {
153153 lookUpBase64Alphabet [63 ] = (byte ) '/' ;
154154 }
155155
156+ /**
157+ * Returns whether or not the <code>octect</code> is in the base 64 alphabet.
158+ *
159+ * @param octect The value to test
160+ * @return <code>true</code> if the value is defined in the the base 64 alphabet, <code>false</code> otherwise.
161+ */
156162 private static boolean isBase64 (byte octect ) {
157163 if (octect == PAD ) {
158164 return true ;
159- } else if (base64Alphabet [octect ] == -1 ) {
165+ } else if (octect < 0 || base64Alphabet [octect ] == -1 ) {
160166 return false ;
161167 } else {
162168 return true ;
Original file line number Diff line number Diff line change 2323import junit .framework .TestCase ;
2424
2525/**
26- * @version $Id: Base64Test.java,v 1.15 2004/04/19 01:14:29 ggregory Exp $
26+ * @version $Id: Base64Test.java,v 1.16 2004/11/24 19:23:25 ggregory Exp $
2727 * @author Apache Software Foundation
2828 */
2929public class Base64Test extends TestCase {
@@ -513,6 +513,17 @@ public void testIgnoringNonBase64InDecode() throws Exception {
513513 assertEquals ("The quick brown fox jumped over the lazy dogs." ,new String (Base64 .decodeBase64 ("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n \r \t %#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes ())));
514514 }
515515
516+ public void testIsArrayByteBase64 () {
517+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {Byte .MIN_VALUE }));
518+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {-125 }));
519+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {-10 }));
520+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {0 }));
521+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {64 , Byte .MAX_VALUE }));
522+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {Byte .MAX_VALUE }));
523+ assertTrue (Base64 .isArrayByteBase64 (new byte [] {'A' }));
524+ assertFalse (Base64 .isArrayByteBase64 (new byte [] {'A' , Byte .MIN_VALUE }));
525+ }
526+
516527 public void testObjectDecodeWithInvalidParameter () throws Exception {
517528 boolean exceptionThrown = false ;
518529
You can’t perform that action at this time.
0 commit comments