lp.test.util
Class TabSeparatedReader

java.lang.Object
  extended by lp.test.util.TabSeparatedReader
All Implemented Interfaces:
Closeable

public class TabSeparatedReader
extends Object
implements Closeable

Reads strings separated by tabs, newline characters or comments from a stream. They are returned one by one by the getNext() method.

Version:
1.0.0
Author:
Martin Slota

Field Summary
private  Reader in
          The stream from which the strings are read.
private  int la
          A lookahead character.
private  StringBuilder sb
          Used to build a string that is returned.
 
Constructor Summary
TabSeparatedReader(Reader in)
          Creates a new instance that reads from the given stream.
 
Method Summary
 void close()
          Closes the underlying Reader.
 String getNext()
          Returns strings separated by tabs, newline characters or comments in the underlying stream one by one.
private  void newLA()
          Reads the next character from the underlying Reader and stores it in la.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

private final Reader in
The stream from which the strings are read.


sb

private final StringBuilder sb
Used to build a string that is returned.


la

private int la
A lookahead character.

Constructor Detail

TabSeparatedReader

public TabSeparatedReader(Reader in)
                   throws IOException
Creates a new instance that reads from the given stream.

Parameters:
in - the stream to read from
Throws:
IOException - if an I/O error occurs while reading the first character from in
Method Detail

close

public void close()
           throws IOException
Closes the underlying Reader.

Specified by:
close in interface Closeable
Throws:
IOException - if a I/O error occurs while closing the underlying Reader

getNext

public String getNext()
               throws IOException
Returns strings separated by tabs, newline characters or comments in the underlying stream one by one. A comment is anything from a '%' character until the next line break. The separating parts of input (tabs, newline characters and comments) are never part of the returned string. A sequence of separating parts is handled as a single separating part (this means that an empty string is never returned). null is returned if the end of stream is reached.

Returns:
the string found or null if the end of input is reached
Throws:
IOException - if a I/O error occurs while reading from the underlying Reader

newLA

private void newLA()
            throws IOException
Reads the next character from the underlying Reader and stores it in la.

Throws:
IOException