1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.util.iterator;
26
27 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.util.logging.Logger;
30
31 /***
32 * Utility class providing an Iterator interface over line-oriented
33 * text input, as a thin wrapper over a BufferedReader.
34 *
35 * @author gojomo
36 */
37 public class LineReadingIterator extends LookaheadIterator<String> {
38 private static final Logger logger =
39 Logger.getLogger(LineReadingIterator.class.getName());
40
41 protected BufferedReader reader = null;
42
43 public LineReadingIterator(BufferedReader r) {
44 reader = r;
45 }
46
47 /***
48 * Loads next line into lookahead spot
49 *
50 * @return whether any item was loaded into next field
51 */
52 protected boolean lookahead() {
53 try {
54 next = this.reader.readLine();
55 if(next == null) {
56
57 reader.close();
58 }
59 return (next!=null);
60 } catch (IOException e) {
61 logger.warning(e.toString());
62 return false;
63 }
64 }
65 }