summaryrefslogtreecommitdiff
path: root/test/files/jvm/manifests-new.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/jvm/manifests-new.scala')
-rw-r--r--test/files/jvm/manifests-new.scala34
1 files changed, 33 insertions, 1 deletions
diff --git a/test/files/jvm/manifests-new.scala b/test/files/jvm/manifests-new.scala
index f730be67bb..3937fdec69 100644
--- a/test/files/jvm/manifests-new.scala
+++ b/test/files/jvm/manifests-new.scala
@@ -56,7 +56,7 @@ object Test1 extends TestUtil {
}
object Test2 {
- import scala.util.Marshal._
+ import Marshal._
println("()="+load[Unit](dump(())))
println("true="+load[Boolean](dump(true)))
println("a="+load[Char](dump('a')))
@@ -88,6 +88,38 @@ object Test2 {
println()
}
+object Marshal {
+ import java.io._
+ import scala.reflect.ClassTag
+
+ def dump[A](o: A)(implicit t: ClassTag[A]): Array[Byte] = {
+ val ba = new ByteArrayOutputStream(512)
+ val out = new ObjectOutputStream(ba)
+ out.writeObject(t)
+ out.writeObject(o)
+ out.close()
+ ba.toByteArray()
+ }
+
+ @throws(classOf[IOException])
+ @throws(classOf[ClassCastException])
+ @throws(classOf[ClassNotFoundException])
+ def load[A](buffer: Array[Byte])(implicit expected: ClassTag[A]): A = {
+ val in = new ObjectInputStream(new ByteArrayInputStream(buffer))
+ val found = in.readObject.asInstanceOf[ClassTag[_]]
+ try {
+ found.runtimeClass.asSubclass(expected.runtimeClass)
+ in.readObject.asInstanceOf[A]
+ } catch {
+ case _: ClassCastException =>
+ in.close()
+ throw new ClassCastException("type mismatch;"+
+ "\n found : "+found+
+ "\n required: "+expected)
+ }
+ }
+}
+
trait TestUtil {
import java.io._
def write[A](o: A): Array[Byte] = {