copyright notices/updates
[sbp.git] / src / edu / berkeley / sbp / chr / CharInput.java
1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp.chr;
4 import java.io.*;
5 import java.util.*;
6 import java.lang.reflect.*;
7 import java.lang.ref.*;
8 import edu.berkeley.sbp.*;
9 import edu.berkeley.sbp.util.*;
10 import edu.berkeley.sbp.misc.*;
11 import edu.berkeley.sbp.Input.Location;
12
13 public class CharInput extends Cartesian.Input<Character> {
14     private final Reader r;
15     
16     public CharInput(String s)                { this(new StringReader(s)); }
17     public CharInput(Reader r)                { this(r, null); }
18     public CharInput(Reader r,      String s) { this.r = new BufferedReader(r); }
19     public CharInput(InputStream i)           { this(i, null); }
20     public CharInput(InputStream i, String s) { this(new InputStreamReader(i), s); }
21     
22     boolean cr = false;
23     private int count = 0;
24     public boolean   isCR() { return cr; }
25     public Character _next() throws IOException {
26         cr = false;
27         int i = r.read();
28         if (i==-1) { System.err.print("\r...done       \r"); return null; }
29         char c = (char)i;
30         cr = c=='\n';
31         if ((count++) % 100 == 0)
32           System.err.print("  " + count + "\r");
33         return c;
34     }
35 }