pal.io
Class FormattedInput

java.lang.Object
  extended by pal.io.FormattedInput
All Implemented Interfaces:
java.io.Serializable

public class FormattedInput
extends java.lang.Object
implements java.io.Serializable

tools to simplify formatted input from an input stream

Version:
$Id: FormattedInput.java,v 1.7 2002/10/14 06:54:25 matt Exp $
Author:
Korbinian Strimmer
See Also:
Serialized Form

Method Summary
static FormattedInput getInstance()
          create new instance of this object (note that there is no public constructor because this class is a singleton!)
 void nextLine(java.io.PushbackReader in)
          go to the beginning of the next line.
 double readDouble(java.io.PushbackReader in)
          read next number from stream and convert it to a double (newline/cr are treated as separators)
 double readDouble(java.io.PushbackReader in, boolean ignoreNewlineCR)
          read next number from stream and convert it to a double
 int readInt(java.io.PushbackReader in)
          read next number from stream and convert it to a int (newline/cr are treated as separators)
 int readInt(java.io.PushbackReader in, boolean ignoreNewlineCR)
          read next number from stream and convert it to a int
 java.lang.String readLabel(java.io.PushbackReader in, int maxLength)
          read sequence label from stream A sequence label is not allowed to contain whitespace and either of :,;()[]{}.
 java.lang.String readLine(java.io.PushbackReader in, boolean keepWhiteSpace)
          read a whole line
 int readNextChar(java.io.PushbackReader input)
          read next character from stream (EOF does not count as character but will throw exception)
 java.lang.String readNumber(java.io.PushbackReader in, boolean ignoreNewlineCR)
           
 java.lang.String readWord(java.io.PushbackReader in)
          read word from stream
 int skipWhiteSpace(java.io.PushbackReader in)
          go to first non-whitespace character
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static FormattedInput getInstance()
create new instance of this object (note that there is no public constructor because this class is a singleton!)


nextLine

public void nextLine(java.io.PushbackReader in)
              throws java.io.IOException
go to the beginning of the next line. Recognized line terminators: Unix: \n, DOS: \r\n, Macintosh: \r

Parameters:
in - input stream
Throws:
java.io.IOException

readLine

public java.lang.String readLine(java.io.PushbackReader in,
                                 boolean keepWhiteSpace)
                          throws java.io.IOException
read a whole line

Parameters:
in - input stream
keepWhiteSpace - keep or drop white space
Returns:
string with content of line
Throws:
java.io.IOException

skipWhiteSpace

public int skipWhiteSpace(java.io.PushbackReader in)
                   throws java.io.IOException
go to first non-whitespace character

Parameters:
in - input stream
Returns:
character or EOF
Throws:
java.io.IOException

readNextChar

public int readNextChar(java.io.PushbackReader input)
                 throws java.io.IOException
read next character from stream (EOF does not count as character but will throw exception)

Parameters:
input - input stream
Returns:
character
Throws:
java.io.IOException

readWord

public java.lang.String readWord(java.io.PushbackReader in)
                          throws java.io.IOException
read word from stream

Parameters:
input - stream
Returns:
word read from stream
Throws:
java.io.IOException

readLabel

public java.lang.String readLabel(java.io.PushbackReader in,
                                  int maxLength)
                           throws java.io.IOException
read sequence label from stream A sequence label is not allowed to contain whitespace and either of :,;()[]{}. Note that newline/cr is NOT counted as white space!!

Parameters:
in - input stream
maxLength - maximum allowed length of label (if negative any length is permitted)
Returns:
label
Throws:
java.io.IOException

readNumber

public java.lang.String readNumber(java.io.PushbackReader in,
                                   boolean ignoreNewlineCR)
                            throws java.io.IOException
Throws:
java.io.IOException

readDouble

public double readDouble(java.io.PushbackReader in)
                  throws java.io.IOException,
                         java.lang.NumberFormatException
read next number from stream and convert it to a double (newline/cr are treated as separators)

Parameters:
in - input stream
Returns:
double
Throws:
java.io.IOException
java.lang.NumberFormatException

readDouble

public double readDouble(java.io.PushbackReader in,
                         boolean ignoreNewlineCR)
                  throws java.io.IOException,
                         java.lang.NumberFormatException
read next number from stream and convert it to a double

Parameters:
in - input stream
ignoreNewlineCR - ignore newline/cr as separator
Returns:
double
Throws:
java.io.IOException
java.lang.NumberFormatException

readInt

public int readInt(java.io.PushbackReader in)
            throws java.io.IOException,
                   java.lang.NumberFormatException
read next number from stream and convert it to a int (newline/cr are treated as separators)

Parameters:
in - input stream
Returns:
integer
Throws:
java.io.IOException
java.lang.NumberFormatException

readInt

public int readInt(java.io.PushbackReader in,
                   boolean ignoreNewlineCR)
            throws java.io.IOException,
                   java.lang.NumberFormatException
read next number from stream and convert it to a int

Parameters:
in - input stream
ignoreNewlineCR - ignore newline/cr as separator
Returns:
integer
Throws:
java.io.IOException
java.lang.NumberFormatException