1 package org.jical; 2 3 import java.io.FileInputStream ; 4 import java.io.InputStreamReader ; 5 import java.io.Reader ; 6 import java.util.Iterator ; 7 11 public class ContentLineIterator implements Iterator { 12 private Iterator m_iterator; 13 14 public ContentLineIterator( Reader reader ) { 15 this( new UnfoldingLineIterator( new LineIterator( reader ) ) ); 16 } 17 public ContentLineIterator( Iterator iterator ) { 18 m_iterator = iterator; 19 } 20 21 public boolean hasNext() { 22 return m_iterator.hasNext(); 23 } 24 public Object next() { 25 if ( hasNext() ) { 26 CharSequence cs = (CharSequence ) 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 { 35 throw new UnsupportedOperationException (); 36 } 37 38 39 public static void main( String [] args ) throws Exception { 40 Iterator it = new ContentLineIterator( new InputStreamReader ( new FileInputStream ( args[0] ) ) ); 41 while ( it.hasNext() ) { 42 ContentLine cl = (ContentLine) it.next(); 43 System.out.println( cl.toString() ); 44 } 45 } 46 } 47 | Popular Tags |