diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-01-17 20:38:24 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-01-17 20:52:25 +0100 |
commit | f931833df8cc69d119f636d8a553941bf7ce2349 (patch) | |
tree | ecf7976b244d11d352c0ea75fba1ad72a497315d /test/files/jvm/manifests-new.scala | |
parent | be5554f0c13879d8b7c361f9956dfc9f0093a0b3 (diff) | |
download | scala-f931833df8cc69d119f636d8a553941bf7ce2349.tar.gz scala-f931833df8cc69d119f636d8a553941bf7ce2349.tar.bz2 scala-f931833df8cc69d119f636d8a553941bf7ce2349.zip |
SI-6811 Misc. removals in util, testing, io, ...
Diffstat (limited to 'test/files/jvm/manifests-new.scala')
-rw-r--r-- | test/files/jvm/manifests-new.scala | 34 |
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] = { |