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 TypeMethodDescriptionvoidvoidintDeprecated.intThis method has been introduced because this class previously skipped over consecutive comments and discarded all but the last.doublecharnext()charcharread()All read attempts pass through this function.chardoubleAttempts to read and parse a double delimited by whitespace.doublereadDouble(String delimiters) Attempts to read and parse a double delimited by whitespace or by any character in delimiters.intAttempts to read and parse an integer delimited by whitespace.intreadInteger(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.voidreadSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence) voidreadSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, boolean stopAtDoubleNewLine) voidreadSequence(StringBuilder sequence, SequenceType sequenceType, String delimiters, int maxSites, String gapCharacters, String missingCharacters, String matchCharacters, String matchSequence, ProgressListener progress) voidreadSequence(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.voidreadSequenceLine(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.voidsetCommentDelimiters(char line) voidsetCommentDelimiters(char start, char stop) voidsetCommentDelimiters(char start, char stop, char line) voidsetCommentDelimiters(char start, char stop, char line, char write, char meta) voidsetCommentWriter(Writer commentWriter) voidsetExpectedInputLength(long l) voidskipCharacters(String skip) Skips over any contiguous characters in skip.voidSkips over any space (plus tabs and returns) in the file.voidSkips to the end of the line.charSkips over the file until a character from delimiters is found.voidSkips char any contiguous characters in skip.voidunreadCharacter(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:
IOExceptionImportException
-
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:
IOExceptionImportException
-
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:
IOExceptionImportException
-
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 readingmaxSites- maximum number of sites to readgapCharacters- 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 toprogress- optional ProgressListener. Must not be null.stopAtDoubleNewLine- if true will stop reading if it encounters two consectutive new line characters.- Throws:
IOExceptionImportException
-
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:
IOExceptionImportException
-
readInteger
Attempts to read and parse an integer delimited by whitespace.- Throws:
IOExceptionImportException
-
readInteger
Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.- Throws:
IOExceptionImportException
-
readDouble
Attempts to read and parse a double delimited by whitespace.- Throws:
IOExceptionImportException
-
readDouble
Attempts to read and parse a double delimited by whitespace or by any character in delimiters.- Throws:
IOExceptionImportException
-
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