scala.actors.remote.JavaSerializer.scala Maven / Gradle / Ivy
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id: JavaSerializer.scala 9110 2006-11-01 16:03:28Z mihaylov $
package scala.actors.remote
import java.io.{ByteArrayInputStream, ByteArrayOutputStream,
ObjectInputStream, ObjectOutputStream}
class JavaSerializer(serv: Service) extends Serializer(serv) {
def serialize(o: AnyRef): Array[Byte] = {
val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(bos)
out.writeObject(o)
out.flush()
bos.toByteArray()
}
def deserialize(bytes: Array[Byte]): AnyRef = {
val bis = new ByteArrayInputStream(bytes)
val in = new ObjectInputStream(bis)
in.readObject()
}
}