From efece9fdb5c268d5a1af5b44cdac198c19eaff87 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 24 Sep 2015 21:56:16 -0400 Subject: add comments warning of InputStream leaks in scala.io.reflect --- src/reflect/scala/reflect/io/Streamable.scala | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/reflect/scala/reflect/io') diff --git a/src/reflect/scala/reflect/io/Streamable.scala b/src/reflect/scala/reflect/io/Streamable.scala index aa47947672..99a14d1fb0 100644 --- a/src/reflect/scala/reflect/io/Streamable.scala +++ b/src/reflect/scala/reflect/io/Streamable.scala @@ -27,6 +27,10 @@ object Streamable { * efficient method implementations. * * ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' + * + * Note that this code was not written with resource management in mind. + * Several methods (such as `chars` and `lines`) create InputStreams they + * don't close */ trait Bytes { def inputStream(): InputStream @@ -82,9 +86,13 @@ object Streamable { */ def creationCodec: Codec = implicitly[Codec] + /** Caller is responsible for closing the returned BufferedSource. */ def chars(codec: Codec): BufferedSource = Source.fromInputStream(inputStream())(codec) + /** Beware! Leaks an InputStream which will not be closed until it gets finalized. */ def lines(): Iterator[String] = lines(creationCodec) + + /** Beware! Leaks an InputStream which will not be closed until it gets finalized. */ def lines(codec: Codec): Iterator[String] = chars(codec).getLines() /** Obtains an InputStreamReader wrapped around a FileInputStream. -- cgit v1.2.3