jebl.evolution.io
Class ImportHelper

java.lang.Object
  extended by jebl.evolution.io.ImportHelper

public class ImportHelper
extends java.lang.Object

A helper class for phylogenetic file format importers

Version:
$Id: ImportHelper.java 931 2008-07-01 01:31:28Z richardmoir $
Author:
Andrew Rambaut, Alexei Drummond

Constructor Summary
ImportHelper(java.io.Reader reader)
          ATTENTION: The ImportHelper never closes the reader passed to the constructor.
ImportHelper(java.io.Reader reader, java.io.Writer commentWriter)
           
 
Method Summary
 void clearLastMetaComment()
           
 void closeReader()
           
 int getLastDelimiter()
           
 java.lang.String getLastMetaComment()
          Deprecated. use getMetaComments() instead
 int getLineNumber()
           
 java.util.List<java.lang.String> getMetaComments()
          This method has been introduced because this class previously skipped over consecutive comments and discarded all but the last.
 double getProgress()
           
 char next()
           
 char nextCharacter()
           
 char read()
          All read attempts pass through this function.
 char readCharacter()
           
 double readDouble()
          Attempts to read and parse a double delimited by whitespace.
 double readDouble(java.lang.String delimiters)
          Attempts to read and parse a double delimited by whitespace or by any character in delimiters.
 int readInteger()
          Attempts to read and parse an integer delimited by whitespace.
 int readInteger(java.lang.String delimiters)
          Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.
 java.lang.String readLine()
          Reads a line, skipping over any comments.
 void readSequence(java.lang.StringBuilder sequence, SequenceType sequenceType, java.lang.String delimiters, int maxSites, java.lang.String gapCharacters, java.lang.String missingCharacters, java.lang.String matchCharacters, java.lang.String matchSequence)
           
 void readSequence(java.lang.StringBuilder sequence, SequenceType sequenceType, java.lang.String delimiters, int maxSites, java.lang.String gapCharacters, java.lang.String missingCharacters, java.lang.String matchCharacters, java.lang.String matchSequence, boolean stopAtDoubleNewLine)
           
 void readSequence(java.lang.StringBuilder sequence, SequenceType sequenceType, java.lang.String delimiters, int maxSites, java.lang.String gapCharacters, java.lang.String missingCharacters, java.lang.String matchCharacters, java.lang.String matchSequence, ProgressListener progress)
           
 void readSequence(java.lang.StringBuilder sequence, SequenceType sequenceType, java.lang.String delimiters, int maxSites, java.lang.String gapCharacters, java.lang.String missingCharacters, java.lang.String matchCharacters, java.lang.String matchSequence, ProgressListener progress, boolean stopAtDoubleNewLine)
          Reads sequence, skipping over any comments and filtering using sequenceType.
 void readSequenceLine(java.lang.StringBuffer sequence, SequenceType sequenceType, java.lang.String delimiters, java.lang.String gapCharacters, java.lang.String missingCharacters, java.lang.String matchCharacters, java.lang.String matchSequence)
          Reads a line of sequence, skipping over any comments and filtering using sequenceType.
 java.lang.String readToken()
          Reads a token stopping when any whitespace or a comment is found.
 java.lang.String readToken(java.lang.String delimiters)
          Reads a token stopping when any whitespace, a comment or when any character in delimiters is found.
 void setCommentDelimiters(char line)
           
 void setCommentDelimiters(char start, char stop)
           
 void setCommentDelimiters(char start, char stop, char line)
           
 void setCommentDelimiters(char start, char stop, char line, char write, char meta)
           
 void setCommentWriter(java.io.Writer commentWriter)
           
 void setExpectedInputLength(long l)
           
 void skipCharacters(java.lang.String skip)
          Skips over any contiguous characters in skip.
 void skipSpace()
          Skips over any space (plus tabs and returns) in the file.
 void skipToEndOfLine()
          Skips to the end of the line.
 char skipUntil(java.lang.String skip)
          Skips over the file until a character from delimiters is found.
 void skipWhile(java.lang.String skip)
          Skips char any contiguous characters in skip.
 void unreadCharacter(char ch)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImportHelper

public ImportHelper(java.io.Reader reader)
ATTENTION: The ImportHelper never closes the reader passed to the constructor. If the reader holds resources (e.g. a FileReader, which holds an open file), then it is the client class' responsibility to close the reader when it has finished using it.

Parameters:
reader -

ImportHelper

public ImportHelper(java.io.Reader reader,
                    java.io.Writer commentWriter)
Method Detail

setExpectedInputLength

public void setExpectedInputLength(long l)

getProgress

public double getProgress()
Returns:
If the length of the input is known (because a file was passed to the constructor), this reports a value between 0.0 and 1.0 indicating the relative read position in the file. Otherwise, this always returns 0.0. This method assumes that all characters in the input are one byte long (to get its estimate, it divides the number of *characters* read by the number of *bytes* in the file). If there is an efficient way to fix this, we should do so :)

closeReader

public void closeReader()
                 throws java.io.IOException
Throws:
java.io.IOException

setCommentDelimiters

public void setCommentDelimiters(char line)

setCommentDelimiters

public void setCommentDelimiters(char start,
                                 char stop)

setCommentDelimiters

public void setCommentDelimiters(char start,
                                 char stop,
                                 char line)

setCommentDelimiters

public void setCommentDelimiters(char start,
                                 char stop,
                                 char line,
                                 char write,
                                 char meta)

setCommentWriter

public void setCommentWriter(java.io.Writer commentWriter)

getLineNumber

public int getLineNumber()

getLastDelimiter

public int getLastDelimiter()

nextCharacter

public char nextCharacter()
                   throws java.io.IOException
Throws:
java.io.IOException

readCharacter

public char readCharacter()
                   throws java.io.IOException
Throws:
java.io.IOException

unreadCharacter

public void unreadCharacter(char ch)

next

public char next()
          throws java.io.IOException
Throws:
java.io.IOException

read

public char read()
          throws java.io.IOException
All read attempts pass through this function.

Returns:
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads a line, skipping over any comments.

Returns:
one line of text
Throws:
java.io.IOException

readSequence

public void readSequence(java.lang.StringBuilder sequence,
                         SequenceType sequenceType,
                         java.lang.String delimiters,
                         int maxSites,
                         java.lang.String gapCharacters,
                         java.lang.String missingCharacters,
                         java.lang.String matchCharacters,
                         java.lang.String matchSequence)
                  throws java.io.IOException,
                         ImportException
Throws:
java.io.IOException
ImportException

readSequence

public void readSequence(java.lang.StringBuilder sequence,
                         SequenceType sequenceType,
                         java.lang.String delimiters,
                         int maxSites,
                         java.lang.String gapCharacters,
                         java.lang.String missingCharacters,
                         java.lang.String matchCharacters,
                         java.lang.String matchSequence,
                         boolean stopAtDoubleNewLine)
                  throws java.io.IOException,
                         ImportException
Throws:
java.io.IOException
ImportException

readSequence

public void readSequence(java.lang.StringBuilder sequence,
                         SequenceType sequenceType,
                         java.lang.String delimiters,
                         int maxSites,
                         java.lang.String gapCharacters,
                         java.lang.String missingCharacters,
                         java.lang.String matchCharacters,
                         java.lang.String matchSequence,
                         ProgressListener progress)
                  throws java.io.IOException,
                         ImportException
Throws:
java.io.IOException
ImportException

readSequence

public void readSequence(java.lang.StringBuilder sequence,
                         SequenceType sequenceType,
                         java.lang.String delimiters,
                         int maxSites,
                         java.lang.String gapCharacters,
                         java.lang.String missingCharacters,
                         java.lang.String matchCharacters,
                         java.lang.String matchSequence,
                         ProgressListener progress,
                         boolean stopAtDoubleNewLine)
                  throws java.io.IOException,
                         ImportException
Reads sequence, skipping over any comments and filtering using sequenceType.

Parameters:
sequence - a StringBuilder into which the sequence is put
sequenceType - the sequenceType of the sequence
delimiters - list of characters that will stop the reading
gapCharacters - list of characters that will be read as gaps
missingCharacters - list of characters that will be read as missing
matchCharacters - list of characters that will be read as matching the matchSequence
matchSequence - the sequence string to match match characters to
maxSites - maximum number of sites to read
progress - optional ProgressListener. Must not be null.
stopAtDoubleNewLine - if true will stop reading if it encounters two consectutive new line characters.
Throws:
java.io.IOException
ImportException

readSequenceLine

public void readSequenceLine(java.lang.StringBuffer sequence,
                             SequenceType sequenceType,
                             java.lang.String delimiters,
                             java.lang.String gapCharacters,
                             java.lang.String missingCharacters,
                             java.lang.String matchCharacters,
                             java.lang.String matchSequence)
                      throws java.io.IOException,
                             ImportException
Reads a line of sequence, skipping over any comments and filtering using sequenceType.

Parameters:
sequence - a StringBuffer into which the sequence is put
sequenceType - the sequenceType of the sequence
delimiters - list of characters that will stop the reading
gapCharacters - list of characters that will be read as gaps
missingCharacters - list of characters that will be read as missing
matchCharacters - list of characters that will be read as matching the matchSequence
matchSequence - the sequence string to match match characters to
Throws:
java.io.IOException
ImportException

readInteger

public int readInteger()
                throws java.io.IOException,
                       ImportException
Attempts to read and parse an integer delimited by whitespace.

Throws:
java.io.IOException
ImportException

readInteger

public int readInteger(java.lang.String delimiters)
                throws java.io.IOException,
                       ImportException
Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.

Throws:
java.io.IOException
ImportException

readDouble

public double readDouble()
                  throws java.io.IOException,
                         ImportException
Attempts to read and parse a double delimited by whitespace.

Throws:
java.io.IOException
ImportException

readDouble

public double readDouble(java.lang.String delimiters)
                  throws java.io.IOException,
                         ImportException
Attempts to read and parse a double delimited by whitespace or by any character in delimiters.

Throws:
java.io.IOException
ImportException

readToken

public java.lang.String readToken()
                           throws java.io.IOException
Reads a token stopping when any whitespace or a comment is found. If the token begins with a quote char then all characters will be included in token until a matching quote is found (including whitespace or comments).

Throws:
java.io.IOException

readToken

public java.lang.String readToken(java.lang.String delimiters)
                           throws java.io.IOException
Reads a token stopping when any whitespace, a comment or when any character in delimiters is found. If the token begins with a quote char then all characters will be included in token until a matching quote is found (including whitespace or comments).

Throws:
java.io.IOException

skipToEndOfLine

public void skipToEndOfLine()
                     throws java.io.IOException
Skips to the end of the line. If a comment is found then this is read.

Throws:
java.io.IOException

skipWhile

public void skipWhile(java.lang.String skip)
               throws java.io.IOException
Skips char any contiguous characters in skip. Will also skip comments.

Throws:
java.io.IOException

skipSpace

public void skipSpace()
               throws java.io.IOException
Skips over any space (plus tabs and returns) in the file. Will also skip comments.

Throws:
java.io.IOException

skipCharacters

public void skipCharacters(java.lang.String skip)
                    throws java.io.IOException
Skips over any contiguous characters in skip. Will also skip comments and space.

Throws:
java.io.IOException

skipUntil

public char skipUntil(java.lang.String skip)
               throws java.io.IOException
Skips over the file until a character from delimiters is found. Returns the delimiter found. Will skip comments and will ignore delimiters within comments.

Throws:
java.io.IOException

getMetaComments

public java.util.List<java.lang.String> getMetaComments()
This method has been introduced because this class previously skipped over consecutive comments and discarded all but the last. This method returns all comments that have been read over since clearLastMetaComment() was last called.

Returns:
List of previously read comments (since clearLastMetaComment was called), never null but may be empty.
See Also:
clearLastMetaComment()

getLastMetaComment

@Deprecated
public java.lang.String getLastMetaComment()
Deprecated. use getMetaComments() instead


clearLastMetaComment

public void clearLastMetaComment()


http://code.google.com/p/jebl2/