Package jebl.evolution.io

# Class ImportHelper

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

public class ImportHelper extends 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

Constructors
Constructor
Description
`ImportHelper(Reader reader)`
ATTENTION: The ImportHelper never closes the reader passed to the constructor.
`ImportHelper(Reader reader, Writer commentWriter)`

## Method Summary

Modifier and Type
Method
Description
`void`
`clearLastMetaComment()`
`void`
`closeReader()`
`int`
`getLastDelimiter()`
`String`
`getLastMetaComment()`
Deprecated.
use `getMetaComments()` instead
`int`
`getLineNumber()`
`List<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(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(String delimiters)`
Attempts to read and parse an integer delimited by whitespace or by any character in delimiters.
`String`
`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.
`String`
`readToken()`
Reads a token stopping when any whitespace or a comment is found.
`String`
`readToken(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(Writer commentWriter)`
`void`
`setExpectedInputLength(long l)`
`void`
`skipCharacters(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(String skip)`
Skips over the file until a character from delimiters is found.
`void`
`skipWhile(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 Details

### ImportHelper

public ImportHelper(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(Reader reader, Writer commentWriter)

## 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

public void closeReader() throws IOException

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

public void setCommentWriter(Writer commentWriter)

### getLineNumber

public int getLineNumber()

### getLastDelimiter

public int getLastDelimiter()

### nextCharacter

public char nextCharacter() throws IOException

Throws:
  `IOException`

### readCharacter

public char readCharacter() throws IOException

Throws:
  `IOException`

### unreadCharacter

public void unreadCharacter(char ch)

### next

public char next() throws IOException

Throws:
  `IOException`

### read

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

Returns:
Throws:
  `IOException`

### readLine

public String readLine() throws IOException
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 put
  `sequenceType` - the sequenceType of the sequence
  `delimiters` - list of characters that will stop the reading
  `maxSites` - maximum number of sites to read
  `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
  `progress` - 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 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:
  `IOException`
  `ImportException`

### readInteger

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

Throws:
  `IOException`
  `ImportException`

### readInteger

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

Throws:
  `IOException`
  `ImportException`

### readDouble

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

Throws:
  `IOException`
  `ImportException`

### readDouble

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

Throws:
  `IOException`
  `ImportException`

### readToken

public String readToken() throws 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:
  `IOException`

### readToken

public String readToken(String delimiters) throws 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:
  `IOException`

### skipToEndOfLine

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

Throws:
  `IOException`

### skipWhile

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

Throws:
  `IOException`

### skipSpace

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

Throws:
  `IOException`

### skipCharacters

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

Throws:
  `IOException`

### skipUntil

public char skipUntil(String skip) throws 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:
  `IOException`

### getMetaComments

public List<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 String getLastMetaComment()
Deprecated.
use `getMetaComments()` instead

### clearLastMetaComment

public void clearLastMetaComment()