org.ourgrid.common.spec.io
Class CharReader

java.lang.Object
  extended by org.ourgrid.common.spec.io.CharReader

public class CharReader
extends java.lang.Object

This is a util Character reader that can read and unread characters and ignore lines.


Field Summary
static char EOF_CHAR
           
static int MAX_UNREAD_CHAR_NUMBER
           
static java.lang.String UNIX_LINE_SEPARATOR
           
 
Constructor Summary
CharReader(java.lang.String file)
          Constructor of a character reader that uses the name of the file do be read.
 
Method Summary
 void closeStreams()
          Closes the reader properlly.
 int getActualLine()
           
 char readChar()
          Read a unique character at a time, including all the spetial structural character.
 void readLine()
          Ignores from the actual position all the characters until the end of line (including it).
 char readNonBlankChar()
          Read only non blank characters ignoring all "Character.isWhitespace()" excepts EOF and this.UNIX_LINE_SEPARATOR
 void unreadChar(char unwishedChar)
          Unread a pre-defined ( this.MAX_UNREAD_CHAR_NUMBER ) number of read characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIX_LINE_SEPARATOR

public static final java.lang.String UNIX_LINE_SEPARATOR
See Also:
Constant Field Values

EOF_CHAR

public static final char EOF_CHAR
See Also:
Constant Field Values

MAX_UNREAD_CHAR_NUMBER

public static final int MAX_UNREAD_CHAR_NUMBER
See Also:
Constant Field Values
Constructor Detail

CharReader

public CharReader(java.lang.String file)
           throws java.io.IOException
Constructor of a character reader that uses the name of the file do be read.

Parameters:
file - the name of the file to be read
Throws:
java.io.IOException - If the file could not be found.
Method Detail

readChar

public char readChar()
              throws java.io.IOException
Read a unique character at a time, including all the spetial structural character. Obs.: Ignores the special character '\r' to turn windows edited files compatible.

Returns:
the read character.
Throws:
java.io.IOException

readNonBlankChar

public char readNonBlankChar()
                      throws java.io.IOException
Read only non blank characters ignoring all "Character.isWhitespace()" excepts EOF and this.UNIX_LINE_SEPARATOR

Returns:
the non blank read character
Throws:
java.io.IOException - if happens any reading problem.

readLine

public void readLine()
              throws java.io.IOException
Ignores from the actual position all the characters until the end of line (including it).

Throws:
java.io.IOException - if happens any reading problem.

unreadChar

public void unreadChar(char unwishedChar)
                throws java.io.IOException
Unread a pre-defined ( this.MAX_UNREAD_CHAR_NUMBER ) number of read characters.

Parameters:
unwishedChar - the temporary unwished char to be inserted back at the reading queue.
Throws:
java.io.IOException - if this method is called more then the maximum times permited (without any character be read)

closeStreams

public void closeStreams()
                  throws java.io.IOException
Closes the reader properlly.

Throws:
java.io.IOException - if any problem related with the closing action happens.

getActualLine

public int getActualLine()
Returns:
returns the number of the line where the reader is now at the file.