summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/io/Socket.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-29 19:11:38 +0000
committerPaul Phillips <paulp@improving.org>2010-01-29 19:11:38 +0000
commitbb149d1b96015d83e58de5ea9b380550267c4f06 (patch)
treeef805e2c02a29e96f5703790c6f91b9cabb091ea /src/compiler/scala/tools/nsc/io/Socket.scala
parentad0fd8bca3c41a15ff688a7ca5e3278fa2ce127b (diff)
downloadscala-bb149d1b96015d83e58de5ea9b380550267c4f06.tar.gz
scala-bb149d1b96015d83e58de5ea9b380550267c4f06.tar.bz2
scala-bb149d1b96015d83e58de5ea9b380550267c4f06.zip
A few compiler IO lib bits I have been needing:...
A few compiler IO lib bits I have been needing: some basic conveniences for directories and sockets, and some cleanups in CompileSocket. Review by community.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io/Socket.scala')
-rw-r--r--src/compiler/scala/tools/nsc/io/Socket.scala34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/io/Socket.scala b/src/compiler/scala/tools/nsc/io/Socket.scala
new file mode 100644
index 0000000000..18ccbda7a2
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/io/Socket.scala
@@ -0,0 +1,34 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2010 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc
+package io
+
+import java.io.{ IOException }
+import java.net.{ URL, MalformedURLException }
+import java.net.{ InetAddress, Socket => JSocket }
+import scala.util.control.Exception._
+
+/** A skeletal only-as-much-as-I-need Socket wrapper.
+ */
+object Socket
+{
+ private val socketExceptions = List(classOf[IOException], classOf[SecurityException])
+
+ class SocketBox(f: () => Socket) {
+ def either: Either[Throwable, Socket] = catching(socketExceptions: _*) either f()
+ def opt: Option[Socket] = catching(socketExceptions: _*) opt f()
+ }
+
+ def apply(host: InetAddress, port: Int) = new SocketBox(() => new Socket(new JSocket(host, port)))
+ def apply(host: String, port: Int) = new SocketBox(() => new Socket(new JSocket(host, port)))
+}
+
+class Socket(jsocket: JSocket) {
+ def getOutputStream() = jsocket.getOutputStream()
+ def getInputStream() = jsocket.getInputStream()
+ def getPort() = jsocket.getPort()
+ def close() = jsocket.close()
+} \ No newline at end of file