Package jebl.evolution.io
Class ImportHelper
java.lang.Object
jebl.evolution.io.ImportHelper
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
ConstructorsConstructorDescriptionImportHelper
(Reader reader) ATTENTION: The ImportHelper never closes the reader passed to the constructor.ImportHelper
(Reader reader, Writer commentWriter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
int
Deprecated.int
This method has been introduced because this class previously skipped over consecutive comments and discarded all but the last.double
char
next()
char
char
read()
All read attempts pass through this function.char
double
Attempts to read and parse a double delimited by whitespace.double
readDouble
(String delimiters) Attempts to read and parse a double delimited by whitespace or by any character in delimiters.int
Attempts to read and parse an integer delimited by whitespace.int
readInteger
(String delimiters) Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.readLine()
Reads a line, skipping over any comments.void
readSequence
(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence) void
readSequence
(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, boolean stopAtDoubleNewLine) void
readSequence
(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, ProgressListener progress) void
readSequence
(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, ProgressListener progress, boolean stopAtDoubleNewLine) Reads sequence, skipping over any comments and filtering using sequenceType.void
readSequenceLine
(StringBuffer sequence, SequenceType sequenceType, String delimiters, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence) Reads a line of sequence, skipping over any comments and filtering using sequenceType.Reads a token stopping when any whitespace or a comment is found.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
(Writer commentWriter) void
setExpectedInputLength
(long l) void
skipCharacters
(String skip) Skips over any contiguous characters in skip.void
Skips over any space (plus tabs and returns) in the file.void
Skips to the end of the line.char
Skips over the file until a character from delimiters is found.void
Skips char any contiguous characters in skip.void
unreadCharacter
(char ch)
-
Constructor Details
-
ImportHelper
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
-
-
Method Details
-
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
- Throws:
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
-
getLineNumber
public int getLineNumber() -
getLastDelimiter
public int getLastDelimiter() -
nextCharacter
- Throws:
IOException
-
readCharacter
- Throws:
IOException
-
unreadCharacter
public void unreadCharacter(char ch) -
next
- Throws:
IOException
-
read
All read attempts pass through this function.- Returns:
- Throws:
IOException
-
readLine
Reads a line, skipping over any comments.- Returns:
- one line of text
- Throws:
IOException
-
readSequence
public void readSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence) throws IOException, ImportException - Throws:
IOException
ImportException
-
readSequence
public void readSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, boolean stopAtDoubleNewLine) throws IOException, ImportException - Throws:
IOException
ImportException
-
readSequence
public void readSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, ProgressListener progress) throws IOException, ImportException - Throws:
IOException
ImportException
-
readSequence
public void readSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, ProgressListener progress, boolean stopAtDoubleNewLine) throws IOException, ImportException Reads sequence, skipping over any comments and filtering using sequenceType.- Parameters:
sequence
- a StringBuilder into which the sequence is putsequenceType
- the sequenceType of the sequencedelimiters
- list of characters that will stop the readinggapCharacters
- list of characters that will be read as gapsmissingCharacters
- list of characters that will be read as missingmatchCharacters
- list of characters that will be read as matching the matchSequencematchSequence
- the sequence string to match match characters tomaxSites
- maximum number of sites to readprogress
- optional ProgressListener. Must not be null.stopAtDoubleNewLine
- if true will stop reading if it encounters two consectutive new line characters.- Throws:
IOException
ImportException
-
readSequenceLine
public void readSequenceLine(StringBuffer sequence, SequenceType sequenceType, String delimiters, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence) throws IOException, ImportException Reads a line of sequence, skipping over any comments and filtering using sequenceType.- Parameters:
sequence
- a StringBuffer into which the sequence is putsequenceType
- the sequenceType of the sequencedelimiters
- list of characters that will stop the readinggapCharacters
- list of characters that will be read as gapsmissingCharacters
- list of characters that will be read as missingmatchCharacters
- list of characters that will be read as matching the matchSequencematchSequence
- the sequence string to match match characters to- Throws:
IOException
ImportException
-
readInteger
Attempts to read and parse an integer delimited by whitespace.- Throws:
IOException
ImportException
-
readInteger
Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.- Throws:
IOException
ImportException
-
readDouble
Attempts to read and parse a double delimited by whitespace.- Throws:
IOException
ImportException
-
readDouble
Attempts to read and parse a double delimited by whitespace or by any character in delimiters.- Throws:
IOException
ImportException
-
readToken
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:
IOException
-
readToken
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:
IOException
-
skipToEndOfLine
Skips to the end of the line. If a comment is found then this is read.- Throws:
IOException
-
skipWhile
Skips char any contiguous characters in skip. Will also skip comments.- Throws:
IOException
-
skipSpace
Skips over any space (plus tabs and returns) in the file. Will also skip comments.- Throws:
IOException
-
skipCharacters
Skips over any contiguous characters in skip. Will also skip comments and space.- Throws:
IOException
-
skipUntil
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:
IOException
-
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 sinceclearLastMetaComment()
was last called.- Returns:
- List of previously read comments (since clearLastMetaComment was called), never null but may be empty.
- See Also:
-
getLastMetaComment
Deprecated.usegetMetaComments()
instead -
clearLastMetaComment
public void clearLastMetaComment()
-
getMetaComments()
instead