summaryrefslogtreecommitdiff
path: root/src/library/scala/util/parsing/CharInputStreamIterator.scala
blob: 2df83ec4d9da8611585d296d615438777722ce3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.util.parsing


import java.io.InputStream
import java.io.{IOException, EOFException}

/** This class ...
 *
 *  @author  Burak Emir
 *  @version 1.0
 *
 *  @deprecated use classes from <a target="contentFrame" href="input.html">
 *              <code>scala.util.parsing.input</code></a> instead.
 */
@deprecated
class CharInputStreamIterator(in: InputStream) extends Iterator[Char] {

  private var ch: Int = _
  private var chSet = false
  private var error: IOException = null

  private def lookahead() {
    try {
      ch = in.read(); chSet = ch >= 0
    } catch {
      case ex: EOFException => ch = -1
      case ex: IOException => ch = 1; error = ex
    }
  }

  def hasNext: Boolean = {
    if (!chSet) lookahead()
    chSet
  }

  def next(): Char = {
    if (!chSet) lookahead()
    chSet = false
    ch.asInstanceOf[Char]
  }
}