I have a bunch of strings in the DB which were encoded with the sun.misc.BASE64Encoder
a while ago.
Now I wanna decode (and encode further strings) with java.util.Base64
.
The difference between these two is that the Sun one added a new line string at each n characters
Example:
Sun Base64: 54y49568uyj304j534w5y
34y0639j6yh93j5h0653j
s45hr68o
JDK8 Base64: 54y49568uyj304j534w5y34y0639j6yh93j5h0653js45hr68o
In order for the JDK decoder to parse these zipped strings, I would need to remove the new line characters.
Questions:
Do I remove \r\n
(Unix) or \n
(Windows) or \r
(old Macs)? Because the strings depend on which machine they were encoded
If I say zippedString.replaceAll("\r", "").replaceAll("\n", "")
how can I make sure that I won't have a \r
chacter in the actual string, resulting in corrupted data?
Is there any other way to create a bridge between these two mechanisms?
There is no white space in Base64 so I would remove the all.
String toDecode = str.replaceAll("\\s+", "");
This removes any ambiguity on how to handle specific newlines or spaces.