Stuart Marks perfect counter-example answer to my original question shows definitely that for at least one edge case the Java 8 java.util.Base64
MIME Encoder delivers a different result than the unsupported, internal Java API sun.misc.BASE64Encoder
.
So let's check that edge case again using the Apache Commons Codec library.
Edge-case test
For the following test I use the sun.misc.BASE64Encoder
implementation of OpenJDK 7 and Apache Commons Codec library 1.14.
public class StuartMarksBase64EncodingEdgeCaseTestForApacheCommonsCodec {
public static void main(String[] args) {
byte[] bytes = new byte[57];
String enc1 = new sun_misc_jdk7.BASE64Encoder().encode(bytes);
String enc2 = new String(org.apache.commons.codec.binary.Base64.encodeBase64(bytes));
System.out.println("enc1 = <" + enc1 + ">");
System.out.println("enc2 = <" + enc2 + ">");
System.out.println(enc1.equals(enc2));
}
}
This then results in the output
enc1 = <AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>
enc2 = <AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>
false
Conclusion
Given the test output I conclude that the Apache Commons Codec Base64 API is not a drop-in replacement to migrate code which uses the sun.misc
Base64 APIs.