1 package uk.org.distorted;
3 import java.io.{InputStreamReader, OutputStreamWriter};
4 import scala.collection.mutable.StringBuilder;
5 import scala.util.control.Breaks;
8 def main(args: Array[String])
10 println("Hello from Scala");
13 for (i <- 0 until args.length) println(f"$i%2d: ${args(i)}%s");
14 //toy match { case toy: Array[Byte] => toy(1) = -1; case _ => () }
17 val conn = new Connection;
19 val rd = new InputStreamReader(new ConnectionInputStream(conn));
20 val wr = new OutputStreamWriter(new ConnectionOutputStream(conn));
22 wr.write("Hello, world!\n"); wr.flush();
24 val buf = new Array[Char](4096);
25 val line = new StringBuilder;
37 val nl = buf.indexOf('\n', pos);
38 if (nl == -1 || nl >= n) {
40 { line.appendAll(buf, pos, n - pos); any = true; }
44 new String(buf, pos, nl - pos);
46 line.appendAll(buf, pos, nl - pos);
47 val s = line.mkString;
48 line.clear(); any = false;
51 println(s"found line `$s'");