blob: db3e400bbbefd618bda7eac67c911bba1ab5151f (
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
28
29
30
31
32
33
34
35
36
37
38
39
|
object InvestmentType extends Enumeration {
val Debt = Value("DEBT")
val Future = Value("FUTURE")
val Equity = Value("EQUITY")
}
object Test {
def main(args: Array[String]) = {
val buf = new java.io.ByteArrayOutputStream
val oos = new java.io.ObjectOutputStream(buf)
InvestmentType.values.foreach {i => oos.writeObject(i)}
oos.flush
oos.close
val ois = new java.io.ObjectInputStream(
new java.io.ByteArrayInputStream(buf.toByteArray))
var obj: Object = null
foreach(ois) { obj =>
obj match {
case InvestmentType.Debt => println("got " + obj)
case InvestmentType.Equity => println("got " + obj)
case InvestmentType.Future => println("got " + obj)
case _ => println("unknown: " + obj + " of: " + obj.getClass)
}
}
}
def foreach(os: java.io.ObjectInputStream)(f: Object => Unit) {
try {
val obj = os.readObject
if (obj != null) {
f(obj)
foreach(os)(f)
}
} catch {
case e: java.io.EOFException => //IGNORE
}
}
}
|