]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/LineReader.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / nls / search / LineReader.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.refactoring.nls.search;
12
13import java.io.BufferedReader;
14import java.io.IOException;
15import java.io.InputStream;
16import java.io.InputStreamReader;
17import java.io.Reader;
18
19
20class 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}