blob: 023e5b3a02c1601d7d64d6efce5139d5521b6b69 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
object Serialize {
@throws(classOf[java.io.IOException])
def write[A](o: A): Array[Byte] = {
val ba = new java.io.ByteArrayOutputStream(512)
val out = new java.io.ObjectOutputStream(ba)
out.writeObject(o)
out.close()
ba.toByteArray()
}
@throws(classOf[java.io.IOException])
@throws(classOf[ClassNotFoundException])
def read[A](buffer: Array[Byte]): A = {
val in =
new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
in.readObject().asInstanceOf[A]
}
}
object Foo {
def obj_foo(x: Int) = { () => x }
}
object Test {
def main(args: Array[String]) {
Serialize.write(Foo.obj_foo(3))
}
}
|