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
Here is a working example using Apache Commons codec:
Maven / sbt repo: commons-codec, commons-codec, 1.8.
You can write or download file from encoded Base64 string:
Worked for me and hopefully for you also...
Another late answer, but my benchmarking shows that Jetty's implementation of Base64 encoder is pretty fast. Not as fast as MiGBase64 but faster than iHarder Base64.
I also did some benchmarks:
These are runs/sec so higher is better.
Guava now has Base64 decoding built in.
Use BaseEncoding.base64().decode()
As for dealing with possible whitespace in input use
BaseEncoding.base64().decode(CharMatcher.WHITESPACE.removeFrom(...));
See this discussion for more information
If You are prefering performance based solution then you can use "MiGBase64"
http://migbase64.sourceforge.net/
As of v6, Java SE ships with JAXB.
javax.xml.bind.DatatypeConverter
has static methods that make this easy. SeeparseBase64Binary()
andprintBase64Binary()
.