@@ -187,8 +187,7 @@ public Base64(int lineLength, byte[] lineSeparator) {
187187 this .encodeSize = 4 ;
188188 }
189189 this .decodeSize = encodeSize - 1 ;
190- byte [] separator = discardWhitespace (lineSeparator );
191- if (separator .length > 0 && isArrayByteBase64 (separator )) {
190+ if (containsBase64Byte (lineSeparator )) {
192191 String sep ;
193192 try {
194193 sep = new String (lineSeparator , "UTF-8" );
@@ -452,42 +451,57 @@ void decode(byte[] in, int inPos, int inAvail) {
452451 }
453452
454453 /**
455- * Returns whether or not the <code>octect </code> is in the base 64 alphabet.
454+ * Returns whether or not the <code>octet </code> is in the base 64 alphabet.
456455 *
457- * @param octect
456+ * @param octet
458457 * The value to test
459458 * @return <code>true</code> if the value is defined in the the base 64 alphabet, <code>false</code> otherwise.
460459 */
461- private static boolean isBase64 (byte octect ) {
462- return octect == PAD || (octect >= 0 && octect < base64ToInt .length && base64ToInt [octect ] != -1 );
460+ private static boolean isBase64 (byte octet ) {
461+ return octet == PAD || (octet >= 0 && octet < base64ToInt .length && base64ToInt [octet ] != -1 );
463462 }
464463
465464 /**
466465 * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
466+ * Currently the method treats whitespace as valid.
467467 *
468- * @param arrayOctect
468+ * @param arrayOctet
469469 * byte array to test
470470 * @return <code>true</code> if all bytes are valid characters in the Base64 alphabet or if the byte array is
471471 * empty; false, otherwise
472472 */
473- public static boolean isArrayByteBase64 (byte [] arrayOctect ) {
473+ public static boolean isArrayByteBase64 (byte [] arrayOctet ) {
474474
475- arrayOctect = discardWhitespace (arrayOctect );
475+ arrayOctet = discardWhitespace (arrayOctet );
476476
477- int length = arrayOctect .length ;
477+ int length = arrayOctet .length ;
478478 if (length == 0 ) {
479- // shouldn't a 0 length array be valid base64 data?
480- // return false;
481- return true ;
479+ return true ;
482480 }
483481 for (int i = 0 ; i < length ; i ++) {
484- if (!isBase64 (arrayOctect [i ])) {
482+ if (!isBase64 (arrayOctet [i ])) {
485483 return false ;
486484 }
487485 }
488486 return true ;
489487 }
490488
489+ /*
490+ * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
491+ *
492+ * @param arrayOctet
493+ * byte array to test
494+ * @return <code>true</code> if any byte is a valid character in the Base64 alphabet; false herwise
495+ */
496+ private static boolean containsBase64Byte (byte [] arrayOctet ) {
497+ for (int i = 0 ; i < arrayOctet .length ; i ++) {
498+ if (isBase64 (arrayOctet [i ])) {
499+ return true ;
500+ }
501+ }
502+ return false ;
503+ }
504+
491505 /**
492506 * Encodes binary data using the base64 algorithm but does not chunk the output.
493507 *
@@ -581,7 +595,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
581595 }
582596
583597 /**
584- * Decodes Base64 data into octects
598+ * Decodes Base64 data into octets
585599 *
586600 * @param base64Data Byte array containing Base64 data
587601 * @return Array containing decoded data.
0 commit comments