I have an image that is Base64 encoded. What is the best way to decode that in Java? Hopefully using only the libraries included with Sun Java 6.
Hope this helps you:
import com.sun.org.apache.xml.internal.security.utils.Base64;
String str="Hello World";
String base64_str=Base64.encode(str.getBytes("UTF-8"));
Or:
String str="Hello World";
String base64_str="";
try
{base64_str=(String)Class.forName("java.util.prefs.Base64").getDeclaredMethod("byteArrayToBase64", new Class[]{byte[].class}).invoke(null, new Object[]{str.getBytes("UTF-8")});
}
catch (Exception ee) {}
java.util.prefs.Base64
works on local rt.jar
,
But it is not in The JRE Class White List
and not in Available classes not listed in the GAE/J white-list
What a pity!
PS. In android, it's easy because that android.util.Base64
has been included since Android API Level 8.