|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ASStreamIterator.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | * :tabSize=8:indentSize=4:noTabs=true:maxLineLen=0: | |
3 | * | |
4 | * Copyright (c) 1998,1999,2000,2001 Tal Davidson. All rights reserved. | |
5 | * | |
6 | * ASStreamIterator.java | |
7 | * by Tal Davidson (davidsont@bigfoot.com) | |
8 | * This file is a part of "Artistic Style" - an indentater and reformatter | |
9 | * of C++, C, and Java source files. | |
10 | * | |
11 | * Ported from C++ to Java by Dirk Moebius (dmoebius@gmx.net). | |
12 | * | |
13 | * The "Artistic Style" project, including all files needed to compile it, | |
14 | * is free software; you can redistribute it and/or use it and/or modify it | |
15 | * under the terms of EITHER the "Artistic License" OR | |
16 | * the GNU Library General Public License as published by the Free Software | |
17 | * Foundation; either version 2 of the License, or (at your option) any later | |
18 | * version. | |
19 | * | |
20 | * This program is distributed in the hope that it will be useful, | |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
23 | * | |
24 | * You should have received a copy of EITHER the "Artistic License" or | |
25 | * the GNU Library General Public License along with this program. | |
26 | */ | |
27 | ||
28 | package net.sourceforge.astyleclipse.astyle; | |
29 | ||
30 | import java.io.BufferedReader; | |
31 | import java.io.InputStream; | |
32 | import java.io.InputStreamReader; | |
33 | import java.io.IOException; | |
34 | import java.io.Reader; | |
35 | ||
36 | /** | |
37 | * A default implementation of a <code>ASSourceIterator</code> that uses an | |
38 | * <code>InputStream</code> or a <code>Reader</code> to read source code | |
39 | * from. | |
40 | */ | |
41 | public class ASStreamIterator implements ASSourceIterator { | |
42 | ||
43 | 0 | public ASStreamIterator(InputStream in) { |
44 | 0 | inStream = new BufferedReader(new InputStreamReader(in)); |
45 | } | |
46 | ||
47 | 0 | public ASStreamIterator(Reader in) { |
48 | 0 | inStream = new BufferedReader(in); |
49 | } | |
50 | ||
51 | 0 | public boolean hasMoreLines() { |
52 | 0 | try { |
53 | 0 | return inStream != null && inStream.ready(); |
54 | } catch (IOException ioex) { | |
55 | 0 | return false; |
56 | } | |
57 | } | |
58 | ||
59 | 0 | public String nextLine() { |
60 | 0 | String line = null; |
61 | 0 | try { |
62 | 0 | line = inStream.readLine(); |
63 | } catch (IOException ioex) { | |
64 | // FIXME: handle exception, or set line="" | |
65 | ; | |
66 | } | |
67 | 0 | if (line == null) { |
68 | 0 | try { |
69 | 0 | inStream.close(); |
70 | } catch (IOException ioex) { | |
71 | //FIXME : handle exception, or set line=""; | |
72 | } | |
73 | 0 | inStream = null; |
74 | 0 | line = ""; // FIXME : return null will cause exception |
75 | } | |
76 | 0 | return line; |
77 | } | |
78 | ||
79 | private BufferedReader inStream; | |
80 | ||
81 | } |
|