Last active
August 29, 2015 14:22
-
-
Save JoshRosen/14ba69ef53af53ef2839 to your computer and use it in GitHub Desktop.
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
scalaVersion := "2.10.4" | |
libraryDependencies += "com.esotericsoftware.kryo" % "kryo" % sys.env.getOrElse("KRYO_VERSION", "2.21") |
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 com.esotericsoftware.kryo.Kryo | |
import com.esotericsoftware.kryo.serializers.JavaSerializer | |
import com.esotericsoftware.kryo.io.{Input, Output} | |
class JavaSerializable extends Serializable | |
object KryoTest { | |
def main(args: Array[String]): Unit = { | |
val kryo = new Kryo() | |
kryo.register(classOf[JavaSerializable], new JavaSerializer()) | |
var output = new Output(100, 100) | |
val objectToWrite = new JavaSerializable | |
kryo.writeClassAndObject(output, objectToWrite) | |
val firstWriteBytes = output.toBytes | |
println("First size is " + firstWriteBytes.length) | |
kryo.readClassAndObject(new Input(firstWriteBytes)) | |
println("Successfully deserialized first copy") | |
//output = new Output(100, 100) | |
output.clear() | |
kryo.reset() | |
kryo.writeClassAndObject(output, objectToWrite) | |
val secondWriteBytes = output.toBytes | |
println("Second size is " + secondWriteBytes.length) | |
kryo.readClassAndObject(new Input(secondWriteBytes)) | |
println("Successfully deserialized second copy") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I run this in
sbt
:The second deserialization crashes.