Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why JDK8's Base64 uses ISO-8859-1?

I'm writing my own BASE64 encoder/decoder for some constrained environments.

And I found that Base64.Encoder#encodeString saying that it uses ISO-8859-1 for construct a String from those encoded bytes.

I perfectly presuming that ISO-8859-1 charset also covers all base64 alphabets.

Is there any possible reason not to use US-ASCII?

like image 963
Jin Kwon Avatar asked Apr 28 '15 10:04

Jin Kwon


1 Answers

I suspect it's more efficient: converting from ISO-8859-1 back to text is just a matter of promoting each byte straight to a char, whereas for ASCII you'd need to check that the byte is valid ASCII. The result for base64 will always be the same, of course.

(That's only a guess, but an educated one. You could always run benchmarks if you want to validate it...)

like image 129
Jon Skeet Avatar answered Jan 01 '23 09:01

Jon Skeet