throw error when Forest created with head()
[sbp.git] / src / edu / berkeley / sbp / chr / CharInput.java
index 95609bc..a03f940 100644 (file)
@@ -59,17 +59,23 @@ public class CharInput extends Cartesian.Input<Character> {
 
     private final RollbackReader r;
     
-    public CharInput(String s)                { this(new StringReader(s)); }
-    public CharInput(Reader r)                { this(r, null); }
-    public CharInput(Reader r,      String s) { this.r = new RollbackReader(new BufferedReader(r)); }
-    public CharInput(InputStream i)           { this(i, null); }
-    public CharInput(InputStream i, String s) { this(new InputStreamReader(i), s); }
+    public CharInput(Reader r,      String s) {
+        this.name = s;
+        this.r = new RollbackReader(new BufferedReader(r));
+    }
+    public CharInput(String s)                  { this(new StringReader(s)); }
+    public CharInput(Reader r)                  { this(r, null); }
+    public CharInput(InputStream i)             { this(i, null); }
+    public CharInput(InputStream i, String s)   { this(new InputStreamReader(i), s); }
+    public CharInput(File f) throws IOException { this(new FileInputStream(f), f.getName()); }
 
     public CharInput(InputStream i, String s, boolean indent) {
         this(new InputStreamReader(i), s);
         this.indent = indent;
     }
+    public String getName() { return name; }
 
+    private String name;
     boolean cr = false;
     boolean indent = false;
     private int count = 0;
@@ -102,10 +108,8 @@ public class CharInput extends Cartesian.Input<Character> {
 
         int i = r.read();
         if (i==-1) {
-            /*System.err.print("\r...done       \r"); */
             if (indent && indentation >= 0) {
                 redent(indentation - lastIndentation);
-                //System.err.println("\r                   \rindent: " + (indentation - lastIndentation));
                 lastIndentation = indentation;
                 indentation = -1;
                 return __next();