com.meyling.principia.io
Class Input

java.lang.Object
  |
  +--com.meyling.principia.io.Input

public class Input
extends Object

This class provides convenient methods for parsing input. TODO offer input stream constructor

Version:
$Revision 0.00.50$
Author:
Michael Meyling

Field Summary
private static char CR
          char marking end of input line
private static char EOF
          char marking end of data
private  StringBuffer line
          current line
private  int lineNumber
          current line number
private static String MARKER
          string for marking current reading position
private  int position
          current reading position
private  StringBuffer source
          holds the data
 
Constructor Summary
Input(String source)
          Constructor using String source.
Input(StringBuffer source)
          Constructor using StringBuffer source.
 
Method Summary
 char getChar()
          Reads a single character and does not change the reading position.
 char getChar(int i)
          Reads a single character and does not change the reading position.
 int getLineNumber()
          Returns the current line number.
 boolean isEmpty()
          Is there no data left for reading?
 char readChar()
          Reads a single character and increments the reading position by one.
 int readCounter()
          Reads the next positive integer made completly out of digits, leading whitespace is skipped.
 String readLetterDigitString()
          Reads the next string containing only letters or digits, leading whitespace is skipped.
 String readQuoted()
          Reads the next quoted string, leading whitespace is skipped.
 String showLinePosition()
          Show reading position.
 void skipWhiteSpace()
          Skips white space, beginning from reading position.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EOF

private static final char EOF
char marking end of data

CR

private static final char CR
char marking end of input line

MARKER

private static final String MARKER
string for marking current reading position

source

private final StringBuffer source
holds the data

line

private StringBuffer line
current line

lineNumber

private int lineNumber
current line number

position

private int position
current reading position
Constructor Detail

Input

public Input(StringBuffer source)
Constructor using StringBuffer source.
Parameters:
source - data source
Throws:
IllegalArgumentException - if argument was an nullpointer

Input

public Input(String source)
Constructor using String source.
Parameters:
source - data source
Throws:
IllegalArgumentException - if argument was an nullpointer
Method Detail

readChar

public final char readChar()
Reads a single character and increments the reading position by one.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

getChar

public final char getChar()
Reads a single character and does not change the reading position.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

getChar

public final char getChar(int i)
Reads a single character and does not change the reading position.
Parameters:
i - offset from current reading position.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

getLineNumber

public final int getLineNumber()
Returns the current line number.
Returns:
current line number

skipWhiteSpace

public final void skipWhiteSpace()
Skips white space, beginning from reading position. Changes reading position to next non white space character.

isEmpty

public final boolean isEmpty()
Is there no data left for reading?
Returns:
is all data read?

readLetterDigitString

public final String readLetterDigitString()
Reads the next string containing only letters or digits, leading whitespace is skipped. Changes reading position.
Returns:
read string
Throws:
IllegalArgumentException - if no such characters could be found

readCounter

public final int readCounter()
Reads the next positive integer made completly out of digits, leading whitespace is skipped. Changes reading position.
Returns:
read integer
Throws:
IllegalArgumentException - if no digits where found or the number was to big for an int

readQuoted

public final String readQuoted()
                        throws IllegalArgumentException
Reads the next quoted string, leading whitespace is skipped. A correctly quoted string could be created by adding a leading and a trailing quote character and doubling each other quote character. The resulting string is dequoted. Changes reading position.
Returns:
deqoted read string
Throws:
IllegalArgumentException - if no correctly quoted string was found

showLinePosition

public final String showLinePosition()
Show reading position.
Returns:
current line with mark at current reading position