Skip to content

Instantly share code, notes, and snippets.

@starkcoffee
Created June 2, 2016 21:10
Show Gist options
  • Save starkcoffee/a8fbea118937f5af9c431c6b5d62e06f to your computer and use it in GitHub Desktop.
Save starkcoffee/a8fbea118937f5af9c431c6b5d62e06f to your computer and use it in GitHub Desktop.
Base64 encoding and back in scala
"prove encoding is a thing" in new Context {
val originalStr = "tschüß"
val base64EncodedStr = Base64.getEncoder.encodeToString(originalStr.getBytes("UTF-8"))
val decodedStr = new String(Base64.getDecoder().decode(base64EncodedStr), "ASCII")
decodedStr ==== originalStr
}
@starkcoffee
Copy link
Author

'tsch����' is not equal to 'tschüß'
Expected :tschüß
Actual   :tsch����

@yzhong52
Copy link

yzhong52 commented Dec 6, 2017

Of cause this won't work, it is encoding as UTF-8 and decoding using ASCII.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment