01: package org.jical;
02:
03: import java.io.FileInputStream;
04: import java.io.InputStreamReader;
05: import java.io.Reader;
06: import java.util.Iterator;
07:
08: //import java.util.Map;
09: //import java.util.regex.Pattern;
10: //import java.util.regex.Matcher;
11:
12: public class ContentLineIterator implements Iterator {
13: private Iterator m_iterator;
14:
15: public ContentLineIterator(Reader reader) {
16: this (new UnfoldingLineIterator(new LineIterator(reader)));
17: }
18:
19: public ContentLineIterator(Iterator iterator) {
20: m_iterator = iterator;
21: }
22:
23: public boolean hasNext() {
24: return m_iterator.hasNext();
25: }
26:
27: public Object next() {
28: if (hasNext()) {
29: CharSequence cs = (CharSequence) m_iterator.next();
30: ContentLine cl = ContentLineParser.parse(cs);
31: if (cl != null) {
32: return cl;
33: }
34: }
35: return null;
36: }
37:
38: public void remove() throws UnsupportedOperationException {
39: throw new UnsupportedOperationException();
40: }
41:
42: public static void main(String[] args) throws Exception {
43: Iterator it = new ContentLineIterator(new InputStreamReader(
44: new FileInputStream(args[0])));
45: while (it.hasNext()) {
46: ContentLine cl = (ContentLine) it.next();
47: System.out.println(cl.toString());
48: }
49: }
50: }
|