litesoft
Diff Revisions
947
vs
948
for /trunk/Java/core/Server/src/org/litesoft/util/LineReaderIterator.java
|
@@ -1,11 +1,11 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.util; |
3 |
3 |
|
|
4 |
|
- |
import java.io.*; |
5 |
|
- |
|
6 |
4 |
|
import org.litesoft.commonfoundation.exceptions.*; |
7 |
5 |
|
import org.litesoft.commonfoundation.iterators.*; |
8 |
6 |
|
|
|
7 |
+ |
import java.io.*; |
|
8 |
+ |
|
9 |
9 |
|
/** |
10 |
10 |
|
* An Iterator representing the results of repeatedly calling readLine |
11 |
11 |
|
* on a BufferedReader. The underlying data source is any Reader.<p> |
|
@@ -14,51 +14,41 @@ |
14 |
14 |
|
* @version 1.0 7/28/01 |
15 |
15 |
|
*/ |
16 |
16 |
|
|
17 |
|
- |
public class LineReaderIterator extends Iterators.AbstractReadOnly<String> |
18 |
|
- |
{ |
|
17 |
+ |
public class LineReaderIterator extends Iterators.AbstractReadOnly<String> { |
19 |
18 |
|
/** |
20 |
19 |
|
* Construct an Iterator representing the results of repeatedly |
21 |
20 |
|
* calling readLine on a BufferedReader.<p> |
22 |
21 |
|
* |
23 |
22 |
|
* @param pReader the underlying data source (null OK). |
24 |
23 |
|
*/ |
25 |
|
- |
public LineReaderIterator( Reader pReader ) |
26 |
|
- |
{ |
|
24 |
+ |
public LineReaderIterator( Reader pReader ) { |
27 |
25 |
|
zReader = Utils.getBufferedReader( pReader ); |
28 |
26 |
|
} |
29 |
27 |
|
|
30 |
28 |
|
private BufferedReader zReader; |
31 |
29 |
|
private String zNextLine = null; |
32 |
30 |
|
|
33 |
|
- |
private boolean loadNextLine() |
34 |
|
- |
{ |
35 |
|
- |
if ( zReader == null ) |
36 |
|
- |
{ |
|
31 |
+ |
private boolean loadNextLine() { |
|
32 |
+ |
if ( zReader == null ) { |
37 |
33 |
|
return false; |
38 |
34 |
|
} |
39 |
|
- |
try |
40 |
|
- |
{ |
41 |
|
- |
if ( null != (zNextLine = zReader.readLine()) ) |
42 |
|
- |
{ |
|
35 |
+ |
try { |
|
36 |
+ |
if ( null != (zNextLine = zReader.readLine()) ) { |
43 |
37 |
|
return true; |
44 |
38 |
|
} |
45 |
39 |
|
} |
46 |
|
- |
catch ( IOException e ) |
47 |
|
- |
{ |
|
40 |
+ |
catch ( IOException e ) { |
48 |
41 |
|
throw new FileSystemException( e ); |
49 |
42 |
|
} |
50 |
43 |
|
closeReader(); |
51 |
44 |
|
return false; |
52 |
45 |
|
} |
53 |
46 |
|
|
54 |
|
- |
private void closeReader() |
55 |
|
- |
{ |
56 |
|
- |
try |
57 |
|
- |
{ |
|
47 |
+ |
private void closeReader() { |
|
48 |
+ |
try { |
58 |
49 |
|
zReader.close(); |
59 |
50 |
|
} |
60 |
|
- |
catch ( IOException ignore ) |
61 |
|
- |
{ |
|
51 |
+ |
catch ( IOException ignore ) { |
62 |
52 |
|
// ignoring... |
63 |
53 |
|
} |
64 |
54 |
|
zReader = null; |
|
@@ -70,10 +60,8 @@ |
70 |
60 |
|
*/ |
71 |
61 |
|
@Override |
72 |
62 |
|
public void finalize() |
73 |
|
- |
throws Throwable |
74 |
|
- |
{ |
75 |
|
- |
if ( zReader != null ) |
76 |
|
- |
{ |
|
63 |
+ |
throws Throwable { |
|
64 |
+ |
if ( zReader != null ) { |
77 |
65 |
|
closeReader(); |
78 |
66 |
|
} |
79 |
67 |
|
super.finalize(); |
|
@@ -88,14 +76,13 @@ |
88 |
76 |
|
* the Reader is closed, hasNext() returns false.<p> |
89 |
77 |
|
* |
90 |
78 |
|
* @return <tt>true</tt>/<tt>false</tt>, if there is another line to be |
91 |
|
- |
* had from next().<p> |
|
79 |
+ |
* had from next().<p> |
92 |
80 |
|
* |
93 |
81 |
|
* @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#hasNext()">java.util.Iterator#hasNext()</a> |
94 |
82 |
|
* @see #next() |
95 |
83 |
|
*/ |
96 |
84 |
|
@Override |
97 |
|
- |
public boolean hasNext() |
98 |
|
- |
{ |
|
85 |
+ |
public boolean hasNext() { |
99 |
86 |
|
return ((zNextLine != null) || loadNextLine()); |
100 |
87 |
|
} |
101 |
88 |
|
|
|
@@ -105,10 +92,8 @@ |
105 |
92 |
|
* @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/Util/Iterator.html#next()">java.util.Iterator#next()</a> |
106 |
93 |
|
*/ |
107 |
94 |
|
@Override |
108 |
|
- |
public String next() |
109 |
|
- |
{ |
110 |
|
- |
if ( !hasNext() ) |
111 |
|
- |
{ |
|
95 |
+ |
public String next() { |
|
96 |
+ |
if ( !hasNext() ) { |
112 |
97 |
|
return super.next(); // throws Exception |
113 |
98 |
|
} |
114 |
99 |
|
String rv = zNextLine; |
|
@@ -122,8 +107,7 @@ |
122 |
107 |
|
* @return A String representation of this. |
123 |
108 |
|
*/ |
124 |
109 |
|
@Override |
125 |
|
- |
public String toString() |
126 |
|
- |
{ |
|
110 |
+ |
public String toString() { |
127 |
111 |
|
return "LineReaderIterator: " + (hasNext() ? "has More" : "at End"); |
128 |
112 |
|
} |
129 |
113 |
|
} |