package uk.org.distorted.tripe;
-import java.io.{InputStream, OutputStream};
+import java.io.{Closeable, File, InputStream, OutputStream};
+import jni.Constants._;
-class Connection {
- val conn = JNI.connect();
- def close() { JNI.close(conn, JNI.CF_CLOSEMASK); }
- override protected def finalize() { close(); }
+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(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, JNI.CF_CLOSERD); }
+ 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(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, JNI.CF_CLOSEWR); }
+ jni.send(conn.conn, buf, start, len);
+ override def close() { jni.close(conn.conn, CF_CLOSEWR); }
}