Recently, I needed to encode and decode some information for a project I was working on. I wrote a quick little snippet to show encoding and decoding a string in the same program.
CODE:
def me = "Jim Shingler"
println "Me: ${me}"
// Encode it
def encoded = me.bytes.encodeBase64()
println "encoded: ${encoded}"
// because I need a string for decoding
StringWriter sw = new StringWriter()
encoded.writeTo(sw)
// Decode it
String decoded = new String(sw.toString().decodeBase64())
assert decoded == me
println "decoded: ${decoded}"
OUTPUT:
Me: Jim Shingler
encoded: SmltIFNoaW5nbGVy
decoded: Jim Shingler
Friday, December 28, 2007
Groovy Encode / Decode
Labels:
Groovy
Tuesday, December 11, 2007
Grails 1.1 RC3 - Released
Grails 1.1 RC-3 has been released and it includes Groovy 1.5.
Wow, This is really getting exciting.
You can download it at http://www.grails.org/Download
Sunday, December 9, 2007
Sunday, December 2, 2007
Grails Exchange 2007 - Presentations posted
The Grails Exchange 2007 Presentations are Podcasts have been posted.
You can find it on the Grails Exchange site: http://grails-exchange.com/. (Just click on the sessions, you will find a PDF of the slides and google video.)
I have listed to many of the Podcasts, It looks like it was a really good conference. I wish I could have been there.
Check it out.
Subscribe to:
Posts (Atom)