test/java/util/Base64/TestBase64.java
Print this page
@@ -20,11 +20,11 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
- * @test 4235519 8004212 8005394 8007298 8006295 8006315 8006530
+ * @test 4235519 8004212 8005394 8007298 8006295 8006315 8006530 8007379 8008925
* @summary tests java.util.Base64
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -105,19 +105,21 @@
checkIAE(new Runnable() { public void run() {
Base64.getDecoder().decode(ByteBuffer.wrap(decoded), ByteBuffer.allocate(1024)); }});
checkIAE(new Runnable() { public void run() {
Base64.getDecoder().decode(ByteBuffer.wrap(decoded), ByteBuffer.allocateDirect(1024)); }});
+ // illegal ending unit
+ checkIAE(new Runnable() { public void run() { Base64.getMimeDecoder().decode("$=#"); }});
+
// test return value from decode(ByteBuffer, ByteBuffer)
testDecBufRet();
// test single-non-base64 character for mime decoding
testSingleNonBase64MimeDec();
// test decoding of unpadded data
testDecodeUnpadded();
-
// test mime decoding with ignored character after padding
testDecodeIgnoredAfterPadding();
}
private static sun.misc.BASE64Encoder sunmisc = new sun.misc.BASE64Encoder();
@@ -382,10 +384,14 @@
// decode(byte[])
byte[] encoded = encM.encode(src[i]);
encoded = Arrays.copyOf(encoded, encoded.length + 1);
encoded[encoded.length - 1] = nonBase64;
checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored");
+ byte[] decoded = new byte[src[i].length];
+ decM.decode(encoded, decoded);
+ checkEqual(decoded, src[i], "Non-base64 char is not ignored");
+
try {
dec.decode(encoded);
throw new RuntimeException("No IAE for non-base64 char");
} catch (IllegalArgumentException iae) {}