diff options
author | Paul Phillips <paulp@improving.org> | 2009-08-17 20:42:33 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-08-17 20:42:33 +0000 |
commit | d0ca666b758fa9f6060361848dc410b81e5cb1ed (patch) | |
tree | f1e3616ca65e28e31f1fe93c6ac5636aa7a3b00e /src | |
parent | 32463342dcd5171d0f274dace6e4e4bfe6780cb0 (diff) | |
download | scala-d0ca666b758fa9f6060361848dc410b81e5cb1ed.tar.gz scala-d0ca666b758fa9f6060361848dc410b81e5cb1ed.tar.bz2 scala-d0ca666b758fa9f6060361848dc410b81e5cb1ed.zip |
Updated BufferedSource to use Iterator.continua...
Updated BufferedSource to use Iterator.continually.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/io/BufferedSource.scala | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/src/library/scala/io/BufferedSource.scala b/src/library/scala/io/BufferedSource.scala index 18c7e84db3..ff1861d9b4 100644 --- a/src/library/scala/io/BufferedSource.scala +++ b/src/library/scala/io/BufferedSource.scala @@ -24,24 +24,9 @@ class BufferedSource(inputStream: InputStream)(implicit codec: Codec = Codec.def def reader() = new InputStreamReader(inputStream, codec.decoder) def bufferedReader() = new BufferedReader(reader(), DefaultBufSize) - // It would be nice if we could do something like this: - // Stream continually getc() takeWhile (_ != -1) map (_.toChar) iterator - // ...but the Stream is not collected so memory grows without bound - - class ContinuallyIterator[T](cond: T => Boolean, body: => T) extends BufferedIterator[T] { - private[this] var hd: T = body - def head = hd - def hasNext = cond(hd) - def next = { - val res = hd - hd = body - res - } - } - override val iter = { val reader = bufferedReader() - new ContinuallyIterator[Int](_ != -1, codec wrap reader.read()) map (_.toChar) + Iterator continually (codec wrap reader.read()) takeWhile (_ != -1) map (_.toChar) } } |