KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jical > ContentLineIterator


1 package org.jical;
2
3 import java.io.FileInputStream JavaDoc;
4 import java.io.InputStreamReader JavaDoc;
5 import java.io.Reader JavaDoc;
6 import java.util.Iterator JavaDoc;
7 //import java.util.Map;
8
//import java.util.regex.Pattern;
9
//import java.util.regex.Matcher;
10

11 public class ContentLineIterator implements Iterator JavaDoc {
12     private Iterator JavaDoc m_iterator;
13
14     public ContentLineIterator( Reader JavaDoc reader ) {
15     this( new UnfoldingLineIterator( new LineIterator( reader ) ) );
16     }
17     public ContentLineIterator( Iterator JavaDoc iterator ) {
18     m_iterator = iterator;
19     }
20
21     public boolean hasNext() {
22     return m_iterator.hasNext();
23     }
24     public Object JavaDoc next() {
25     if ( hasNext() ) {
26         CharSequence JavaDoc cs = (CharSequence JavaDoc) m_iterator.next();
27         ContentLine cl = ContentLineParser.parse( cs );
28         if ( cl != null ) {
29         return cl;
30         }
31     }
32     return null;
33     }
34     public void remove() throws UnsupportedOperationException JavaDoc {
35     throw new UnsupportedOperationException JavaDoc();
36     }
37
38
39     public static void main( String JavaDoc[] args ) throws Exception JavaDoc {
40     Iterator JavaDoc it = new ContentLineIterator( new InputStreamReader JavaDoc( new FileInputStream JavaDoc ( args[0] ) ) );
41     while ( it.hasNext() ) {
42         ContentLine cl = (ContentLine) it.next();
43         System.out.println( cl.toString() );
44     }
45     }
46 }
47
Popular Tags