Decode Base64 data in Java

前端 未结 20 1450
时光说笑
时光说笑 2020-11-21 06:04

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.

20条回答
  •  攒了一身酷
    2020-11-21 06:45

    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.

    import org.eclipse.jetty.util.B64Code;
    
    final String decoded = B64Code.decode(encoded, "UTF-8");
    

    I also did some benchmarks:

          library     |    encode    |    decode   
    ------------------+--------------+-------------
     'MiGBase64'      |  10146001.00 |  6426446.00
     'Jetty B64Code'  |   8846191.00 |  3101361.75
     'iHarder Base64' |   3259590.50 |  2505280.00
     'Commons-Codec'  |    241318.04 |   255179.96
    

    These are runs/sec so higher is better.

提交回复
热议问题