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.
相关问题
- Views base64 encoded blob in HTML with PHP
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Hope this helps you:
Or:
java.util.prefs.Base64
works on localrt.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.Specifically in Commons Codec: class
Base64
todecode(byte[] array)
orencode(byte[] array)
The Java 8 implementation of
java.util.Base64
has no dependencies on other Java 8 specific classes.I am not certain if this will work for Java 6 project, but it is possible to copy and paste the
Base64.java
file into a Java 7 project and compile it with no modification other than importing java.util.Arrays andjava.util.Objects
.Note the Base64.java file is covered by the GNU GPL2
Here's my own implementation, if it could be useful to someone :
My solution is fastest and easiest.
As of Java 8, there is an officially supported API for Base64 encoding and decoding. In time this will probably become the default choice.
The API includes the class
java.util.Base64
and its nested classes. It supports three different flavors: basic, URL safe, and MIME.Sample code using the "basic" encoding:
The documentation for
java.util.Base64
includes several more methods for configuring encoders and decoders, and for using different classes as inputs and outputs (byte arrays, strings, ByteBuffers, java.io streams).