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