X-Git-Url: https://git.distorted.org.uk/~mdw/tripe-android/blobdiff_plain/7eb3f62e2ea97fab63080e92ebf95a65c95714a1..ad64fbfa301eaddc1a067e78743adcd4c1d1dd8d:/sock.scala diff --git a/sock.scala b/sock.scala deleted file mode 100644 index 1b52bf1..0000000 --- a/sock.scala +++ /dev/null @@ -1,37 +0,0 @@ -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); } -}