<commit_before>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.io

import java.io.{ InputStream, BufferedReader, InputStreamReader }
import Source.DefaultBufSize

/** This object provides convenience methods to create an iterable
 *  representation of a source file.
 *
 *  @author  <NAME>, <NAME>
 */
class BufferedSource(inputStream: InputStream)(implicit codec: Codec = Codec.default) extends Source
{
  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)
  }
}
<commit_msg>Updated BufferedSource to use Iterator.continua...<commit_after>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.io

import java.io.{ InputStream, BufferedReader, InputStreamReader }
import Source.DefaultBufSize

/** This object provides convenience methods to create an iterable
 *  representation of a source file.
 *
 *  @author  <NAME>, <NAME>
 */
class BufferedSource(inputStream: InputStream)(implicit codec: Codec = Codec.default) extends Source
{
  def reader() = new InputStreamReader(inputStream, codec.decoder)
  def bufferedReader() = new BufferedReader(reader(), DefaultBufSize)

  override val iter = {
    val reader = bufferedReader()
    Iterator continually (codec wrap reader.read()) takeWhile (_ != -1) map (_.toChar)
  }
}

{'fraction_non_alphanumeric': 0.11961392623233368, 'fraction_numerical': 0.006549465701482247, 'mean_word_length': 1.438655462184874, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138227', 'n_tokens_mistral': 801, 'n_tokens_neox': 757, 'n_words': 194}