1 11 package org.eclipse.jdt.internal.ui.refactoring.nls.search; 12 13 import java.io.BufferedReader ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.InputStreamReader ; 17 import java.io.Reader ; 18 19 20 class LineReader extends Object { 21 protected static final int LF= '\n'; 22 protected static final int CR= '\r'; 23 24 private BufferedReader fReader; 25 26 protected int fPushbackChar; 27 protected boolean fPushback; 28 29 public LineReader(InputStream in, String encoding) throws IOException { 30 this(new InputStreamReader (in, encoding)); 31 } 32 33 public LineReader(Reader reader) { 34 fPushback= false; 35 fReader= new BufferedReader (reader); 36 } 37 38 public int readLine(StringBuffer sb) throws IOException { 39 int ch= -1; 40 sb.setLength(0); 41 if (fPushback) { 42 ch= fPushbackChar; 43 fPushback= false; 44 } else 45 ch= fReader.read(); 46 while (ch >= 0) { 47 if (ch == LF) 48 return 1; 49 if (ch == CR) { 50 ch= fReader.read(); 51 if (ch == LF) 52 return 2; 53 else { 54 fPushbackChar= ch; 55 fPushback= true; 56 return 1; 57 } 58 } 59 sb.append((char) ch); 60 ch= fReader.read(); 61 } 62 return -1; 63 } 64 65 public void close() throws IOException { 66 fReader.close(); 67 } 68 } 69 | Popular Tags |