I needed to convert some strings using Base64 encoding, and I was glad to see that I did not need to run my own converter. Java provides one javax.xml.bind.DataConverter . However, he has some problems. Here is the output of my time using JPL REPL:
>>> import javax.xml.bind.DatatypeConverter as DC >>> import java.lang.String as String >>> def foo(text): ... return DC.printBase64Binary(DC.parseBase64Binary(String(text))) ... >>> foo("hello") 'hell' >>> foo("This, it a punctuated sentence.") 'Thisitsapunctuatedsenten' >>> foo("\"foo\" \"bar\"") 'foob' >>> foo("\"foo\" \"bar\"12") 'foobar12' >>> foo("\"foo\" \"bar\"1") 'foob'
As you can see, it does not process non-alphanumeric characters at all, and also often - but not always - trims a string with two characters.
I think the time has come to just write my own class, but now I'm worried that either: a) I can not read javadoc or something b) the class does not work as expected.
So any help is much appreciated; thanks in advance.
java encoding base64 decoding
tsm
source share