1 package SnowMailClient.utils; 2 3 import java.util.*; 4 import java.io.*; 5 6 7 10 public class NumberedLineReader extends BufferedReader 11 { 12 private int lineNumber = 0; 13 private String lastLine = null; 14 16 private boolean undo = false; 17 18 19 public NumberedLineReader(String cont) 20 { 21 super( new StringReader( cont ) ); 22 } 24 25 public final String readLine() throws IOException 26 { 27 if(undo) 28 { 29 undo = false; 30 } 31 else 32 { 33 lineNumber++; 34 lastLine = super.readLine(); 35 } 36 return lastLine; 37 } 38 39 42 public final void undoRead() 43 { 44 if(undo==true) throw new RuntimeException ("Only one undo allowed !"); 45 if(lastLine==null) throw new RuntimeException ("No line to undo !"); 46 this.undo = true; 47 } 48 49 public final String getLastLineCached() { return lastLine; } 50 51 public final int getLineNumber() { return lineNumber; } 52 53 } | Popular Tags |