Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created December 1, 2010 17:45
Show Gist options
  • Select an option

  • Save debasishg/723886 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/723886 to your computer and use it in GitHub Desktop.
scala> import sbinary._
import sbinary._
scala> import sbinary.Operations._
import sbinary.Operations._
scala> import sbinary.DefaultProtocol._
import sbinary.DefaultProtocol._
scala> toByteArray[Long](1291224466794l)
res0: Array[Byte] = Array(0, 0, 1, 44, -94, -7, -59, 106)
scala> new String(res0, "UTF-8")
res1: java.lang.String = ,��
scala> res1.getBytes("UTF-8")
res2: Array[Byte] = Array(0, 0, 1, 44, -17, -65, -67, -17, -65, -67)
scala> import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.binary.Base64
scala> import org.apache.commons.codec.binary.Base64._
import org.apache.commons.codec.binary.Base64._
scala> encodeBase64URLSafeString(res0)
res3: java.lang.String = AAABLKL5xWo
scala> val b64 = new Base64(true)
b64: org.apache.commons.codec.binary.Base64 = org.apache.commons.codec.binary.Base64@1eaf25d
scala> b64.decode(res3)
res4: Array[Byte] = Array(0, 0, 1, 44, -94, -7, -59, 106)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment