scriptella.expression
Class LineIterator

java.lang.Object
  extended by scriptella.expression.LineIterator
All Implemented Interfaces:
java.io.Closeable, java.util.Iterator<java.lang.String>

public class LineIterator
extends java.lang.Object
implements java.util.Iterator<java.lang.String>, java.io.Closeable

An Iterator over the lines in a Reader, additionally properties substitution is performed.

This class change the contract of hasNext() method by throwing RuntimeIOException on IOException.

Decorators should override format(String) method.

This class is not threadsafe.

Version:
1.0
Author:
Fyodor Kupolov
See Also:
PropertiesSubstitutor

Constructor Summary
LineIterator(java.io.Reader reader)
           
LineIterator(java.io.Reader reader, PropertiesSubstitutor substitutor)
           
LineIterator(java.io.Reader reader, PropertiesSubstitutor substitutor, boolean trimLines)
          Constructs iterator.
 
Method Summary
 void close()
           
protected  java.lang.String format(java.lang.String line)
          Applies additional formatting to the line read.
 java.lang.String getLineAt(int n)
          Returns specified line or null if EOF occured.
 boolean hasNext()
           
 java.lang.String next()
          Returns the next avalable line in a reader.
 void remove()
           
 int skip(int n)
          Skips N lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineIterator

public LineIterator(java.io.Reader reader)

LineIterator

public LineIterator(java.io.Reader reader,
                    PropertiesSubstitutor substitutor)

LineIterator

public LineIterator(java.io.Reader reader,
                    PropertiesSubstitutor substitutor,
                    boolean trimLines)
Constructs iterator.

Parameters:
reader - reader to iterate.
substitutor - substitutor to use to expand properties or null to disable substitution.
trimLines - true if the returned lines should be trimmed.
Method Detail

hasNext

public boolean hasNext()
                throws RuntimeIOException
Specified by:
hasNext in interface java.util.Iterator<java.lang.String>
Returns:
true if a line is available for reading by next()
Throws:
RuntimeIOException - if IO error occurs.

format

protected java.lang.String format(java.lang.String line)
Applies additional formatting to the line read.

May be overriden by decorators.

Parameters:
line - line of text, nulls allowed.
Returns:
formatted line.

next

public java.lang.String next()
                      throws RuntimeIOException,
                             java.util.NoSuchElementException
Returns the next avalable line in a reader.

Specified by:
next in interface java.util.Iterator<java.lang.String>
Returns:
the next avalable line in a reader.
Throws:
RuntimeIOException - if IO error occurs.
java.util.NoSuchElementException - if has no more elements.

skip

public int skip(int n)
Skips N lines.

Parameters:
n - number of lines to skip.
Returns:
the actual number of lines skipped.

getLineAt

public java.lang.String getLineAt(int n)
Returns specified line or null if EOF occured.

Parameters:
n - line number relative to the current line in the input. n>=0
Returns:
line n.

remove

public void remove()
            throws java.lang.UnsupportedOperationException
Specified by:
remove in interface java.util.Iterator<java.lang.String>
Throws:
java.lang.UnsupportedOperationException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException


Copyright © Copyright 2006-2009 The Scriptella Project Team.