Hilbert II - Version 0.03.01

org.qedeq.kernel.utility
Class TextInput

java.lang.Object
  extended byjava.io.InputStream
      extended byorg.qedeq.kernel.utility.TextInput

public final class TextInput
extends InputStream

This class provides convenient methods for parsing input. TODO mime 20050426: offer input stream constructor? TODO mime 20060330: decorate normal java.io.InputStream or other???

Version:
$Revision: 1.14 $

Field Summary
static char CR
          Char marking end of input line.
static int EOF
          Char marking end of data.
 
Constructor Summary
TextInput(File file)
          Constructor using StringBuffer source.
TextInput(File file, URL address)
          Constructor using StringBuffer source.
TextInput(String source)
          Constructor using String source.
TextInput(StringBuffer source)
          Constructor using StringBuffer source.
TextInput(URL url)
          Constructor using URL source.
 
Method Summary
 URL getAddress()
          Get address (or something to identify it) of input source.
 int getChar()
          Reads a single character and does not change the reading position.
 int getChar(int skip)
          Reads a single character and does not change the reading position.
 int getColumn()
          Returns the current column number.
 String getLine()
          Returns the current line.
 URL getLocalAddress()
          Get local address (or something to identify it) of input source.
 int getMaximumPosition()
          Returns the highest position number possible.
 int getPosition()
          Returns the current position.
 int getRow()
          Returns the current line number.
 boolean isEmpty()
          Is there no data left for reading?
 boolean isEmpty(int skip)
          Is there no data left for reading after skipping?
 int read()
          Reads a single character and increments the reading position by one.
 String readCounter()
          Reads the next (big) integer, leading whitespace is skipped.
 int readInverse()
          Decrements the reading position by one and reads a single character.
 String readLetterDigitString()
          Reads the next string containing only letters or digits, leading whitespace is skipped.
 String readNextAttributeValue()
          Reads attribute value out of XML stream.
 String readNextXmlName()
          Reads tag or attribute name out of XML stream.
 String readQuoted()
          Reads the next quoted string, leading whitespace is skipped.
 String readString(int number)
          Reads a given amount of characters and increments the reading position accordingly.
 void setColumn(int column)
          Sets the current column position (and indirectly the position).
 void setPosition(int position)
          Sets the current position (and indirectly the line number).
 void setRow(int row)
          Sets the current line number (and indirectly the position).
 String showLinePosition()
          Show reading position.
 void skipBackToBeginOfXmlTag()
          Skip current position back to beginning of an XML tag.
 void skipForwardToEndOfXmlTag()
          Skip current position forward to end of an XML tag.
 void skipWhiteSpace()
          Skips white space, beginning from reading position.
 void skipWhiteSpaceInverse()
          Skips white space, beginning from reading position.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

public static final int EOF
Char marking end of data.

See Also:
Constant Field Values

CR

public static final char CR
Char marking end of input line.

See Also:
Constant Field Values
Constructor Detail

TextInput

public TextInput(File file)
          throws IOException
Constructor using StringBuffer source.

Parameters:
file - Data source.
Throws:
IOException - File reading failed.
NullPointerException - One argument was a null pointer.

TextInput

public TextInput(File file,
                 URL address)
          throws IOException
Constructor using StringBuffer source.

Parameters:
file - Data source.
address - For identifying source.
Throws:
IOException - File reading failed.
NullPointerException - Argument was a null pointer.

TextInput

public TextInput(StringBuffer source)
Constructor using StringBuffer source.

Parameters:
source - data source
Throws:
NullPointerException - Argument was a null pointer.

TextInput

public TextInput(String source)
Constructor using String source.

Parameters:
source - data source
Throws:
NullPointerException - Argument was a null pointer.

TextInput

public TextInput(URL url)
          throws IOException
Constructor using URL source.

Parameters:
url - Data source.
Throws:
IOException - File reading failed.
NullPointerException - One argument was a null pointer.
Method Detail

read

public final int read()
Reads a single character and increments the reading position by one. If no characters are left, -1 is returned. Otherwise a cast to char gives the character read.

Returns:
Character read, if there are no more chars -1 is returned.

readInverse

public final int readInverse()
Decrements the reading position by one and reads a single character. If no characters are left, -1 is returned. Otherwise a cast to char gives the character read.

Returns:
Character read, if there are no more chars -1 is returned.

readString

public final String readString(int number)
Reads a given amount of characters and increments the reading position accordingly.

Parameters:
number - amount of characters to read
Returns:
string read

getChar

public final int getChar()
Reads a single character and does not change the reading position. If no characters are left, -1 is returned. Otherwise a cast to char gives the character read.

Returns:
Character read at current position, if there are no more chars -1 is returned

getChar

public final int getChar(int skip)
Reads a single character and does not change the reading position. If offset addition leads out of the source, -1 is returned. Otherwise a cast to char gives the character read.

Parameters:
skip - Offset from current reading position. Maybe negative.
Returns:
Character read, if position is out of scope -1 is returned.

skipWhiteSpace

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


skipWhiteSpaceInverse

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


skipBackToBeginOfXmlTag

public final void skipBackToBeginOfXmlTag()
Skip current position back to beginning of an XML tag. This is mainly something like <tagName.

Throws:
IllegalArgumentException - No begin of XML tag found.

skipForwardToEndOfXmlTag

public final void skipForwardToEndOfXmlTag()
Skip current position forward to end of an XML tag. This is mainly something like >. Quoted data is skipped.

Throws:
IllegalArgumentException - No en of XML tag found.

readNextXmlName

public final String readNextXmlName()
Reads tag or attribute name out of XML stream. Whitespace is skipped and characters are read till "=" or ">" or whitespace is found.

Returns:
Name of tag or attribute.
Throws:
IllegalArgumentException - Next non white space character is "=" or ">".

readNextAttributeValue

public final String readNextAttributeValue()
Reads attribute value out of XML stream. Whitespace is skipped and an "=" is expected to follow. Again whitespace is skipped. If no quotation mark follows characters are read till whitespace or ">" occurs. Otherwise data is read till an ending quotation mark comes.

Returns:
Value read. TODO mime 20050503: do any transformations like &lt; into <?

isEmpty

public final boolean isEmpty()
Is there no data left for reading?

Returns:
is all data read?

isEmpty

public final boolean isEmpty(int skip)
Is there no data left for reading after skipping?

Parameters:
skip - Add this number to current position.
Returns:
Is data empty at that new position?

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 String readCounter()
Reads the next (big) integer, leading whitespace is skipped. The first character might be a minus sign, the rest must be digits. Leading zero digits are not allowed, also "-0" is not accepted.

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()
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:
Dequoted string read.
Throws:
IllegalArgumentException - No correctly quoted string was found.

getRow

public final int getRow()
Returns the current line number.

Returns:
Current line number (starting with line 1).

getColumn

public final int getColumn()
Returns the current column number.

Returns:
Current column number (starting with line 1).

getLine

public final String getLine()
Returns the current line.

Returns:
Current line.

getPosition

public final int getPosition()
Returns the current position. Starting with 0.

Returns:
Current position.

getMaximumPosition

public final int getMaximumPosition()
Returns the highest position number possible. This is equal to the length of the source.

Returns:
Maximum position.

setPosition

public final void setPosition(int position)
Sets the current position (and indirectly the line number).

Parameters:
position - Set current position to this value.

setRow

public final void setRow(int row)
Sets the current line number (and indirectly the position).

Parameters:
row - Move to this line number.

setColumn

public final void setColumn(int column)
Sets the current column position (and indirectly the position). If column is out of range the minimum value (1) or the maximum possible column value is taken.

Parameters:
column - Move to this column. First column has the number one.

getAddress

public final URL getAddress()
Get address (or something to identify it) of input source.

Returns:
Address of input source.

getLocalAddress

public final URL getLocalAddress()
Get local address (or something to identify it) of input source.

Returns:
Local address of input source.

showLinePosition

public final String showLinePosition()
Show reading position.

Returns:
current line with mark at current reading position

Hilbert II - Version 0.03.01

©left GNU General Public Licence
All Rights Reserved.