+++ /dev/null
-package uk.org.distorted.tripe;
-
-import java.io.{Closeable, File, InputStream, OutputStream};
-import jni.Constants._;
-
-class Connection(path: File) extends Closeable {
- def this(path: String) { this(new File(path)); }
- val conn = jni.connect(path.getPath);
- override def close() { jni.close(conn, CF_CLOSEMASK); }
- lazy val input = new ConnectionInputStream(this);
- lazy val output = new ConnectionOutputStream(this);
- override protected def finalize() { super.finalize(); close(); }
-}
-
-class ConnectionInputStream(val conn: Connection) extends InputStream {
- override def read(): Int = {
- val buf = new Array[Byte](1);
- val n = read(buf, 0, 1);
- if (n < 0) -1 else buf(0)&0xff;
- }
- override def read(buf: Array[Byte]): Int =
- read(buf, 0, buf.length);
- override def read(buf: Array[Byte], start: Int, len: Int) =
- jni.recv(conn.conn, buf, start, len);
- override def close() { jni.close(conn.conn, CF_CLOSERD); }
-}
-
-class ConnectionOutputStream(val conn: Connection) extends OutputStream {
- override def write(b: Int) = {
- val buf = Array[Byte](b.toByte);
- write(buf, 0, 1);
- }
- override def write(buf: Array[Byte]) { write(buf, 0, buf.length); }
- override def write(buf: Array[Byte], start: Int, len: Int) =
- jni.send(conn.conn, buf, start, len);
- override def close() { jni.close(conn.conn, CF_CLOSEWR); }
-}