Created
April 30, 2015 19:34
-
-
Save bradkarels/6ec5e46e4737485c9694 to your computer and use it in GitHub Desktop.
Spark Chill Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayOutputStream | |
import java.io.ObjectOutputStream | |
import java.io.Serializable | |
import com.twitter.chill.{Input, Output, ScalaKryoInstantiator} | |
class Person extends Serializable { | |
var name: String = "" | |
def this(name:String) { | |
this() | |
this.name = name | |
} | |
} | |
object Person { | |
def apply(name: String) = new Person(name) | |
} | |
val p0:Person = Person("p0") | |
val instantiator = new ScalaKryoInstantiator | |
instantiator.setRegistrationRequired(false) | |
val kryo = instantiator.newKryo() | |
val baos:ByteArrayOutputStream = new ByteArrayOutputStream() | |
val output = new Output(baos) | |
kryo.writeObject(output, p0) | |
output.close | |
val bytes:Array[Byte] = output.toBytes | |
val deserialized = kryo.readObject(new Input(bytes), classOf[Person]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment