From a67b62698d7a8768c6fb17af127f3061f59649f7 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 11 Mar 2013 20:22:04 -0700 Subject: Close after slurping (fixes SI-7244) Since slurp by definition is the noise made by the straw when the cup is empty and all milk shake is consumed, we can safely close after slurping. Use case was deleting a test artifact on Windows. --- src/reflect/scala/reflect/io/Streamable.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/reflect/scala/reflect/io/Streamable.scala b/src/reflect/scala/reflect/io/Streamable.scala index 6184c6776a..1d51ad7f54 100644 --- a/src/reflect/scala/reflect/io/Streamable.scala +++ b/src/reflect/scala/reflect/io/Streamable.scala @@ -106,7 +106,10 @@ object Streamable { /** Convenience function to import entire file into a String. */ def slurp(): String = slurp(creationCodec) - def slurp(codec: Codec) = chars(codec).mkString + def slurp(codec: Codec) = { + val src = chars(codec) + try src.mkString finally src.close() // Always Be Closing + } } /** Call a function on something Closeable, finally closing it. */ -- cgit v1.2.3