summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/io/Socket.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-10 19:51:38 +0000
committerPaul Phillips <paulp@improving.org>2010-02-10 19:51:38 +0000
commit6e76af56f708d345bda2fff580634107945ef3fb (patch)
tree563058a03d54463fbe9139e8f9f74db23a944400 /src/compiler/scala/tools/nsc/io/Socket.scala
parent06ae221de943d7258dfa2ffcbc6c59fe9493497f (diff)
downloadscala-6e76af56f708d345bda2fff580634107945ef3fb.tar.gz
scala-6e76af56f708d345bda2fff580634107945ef3fb.tar.bz2
scala-6e76af56f708d345bda2fff580634107945ef3fb.zip
More work on classpaths.
to have command line options following source files, at the price of temporarily breaking tools/pathResolver. Working my way through all the usages of classpath in trunk zeroing in on fully consistent handling. Review by community.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io/Socket.scala')
-rw-r--r--src/compiler/scala/tools/nsc/io/Socket.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/io/Socket.scala b/src/compiler/scala/tools/nsc/io/Socket.scala
index 18ccbda7a2..e883c71b8e 100644
--- a/src/compiler/scala/tools/nsc/io/Socket.scala
+++ b/src/compiler/scala/tools/nsc/io/Socket.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc
package io
-import java.io.{ IOException }
+import java.io.{ IOException, InputStreamReader, BufferedReader, PrintWriter }
import java.net.{ URL, MalformedURLException }
import java.net.{ InetAddress, Socket => JSocket }
import scala.util.control.Exception._
@@ -31,4 +31,16 @@ class Socket(jsocket: JSocket) {
def getInputStream() = jsocket.getInputStream()
def getPort() = jsocket.getPort()
def close() = jsocket.close()
+
+ /** Creates an InputStream and applies the closure, automatically closing it on completion.
+ */
+ def applyReaderAndWriter[T](f: (BufferedReader, PrintWriter) => T): T = {
+ val out = new PrintWriter(getOutputStream(), true)
+ val in = new BufferedReader(new InputStreamReader(getInputStream()))
+ try f(in, out)
+ finally {
+ in.close()
+ out.close()
+ }
+ }
} \ No newline at end of file