From 6e76af56f708d345bda2fff580634107945ef3fb Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 10 Feb 2010 19:51:38 +0000 Subject: 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. --- src/compiler/scala/tools/nsc/io/Socket.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/compiler/scala/tools/nsc/io/Socket.scala') 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 -- cgit v1.2.3