Class StreamReader
- All Implemented Interfaces:
EventListener
,SequenceIterator
,ParseErrorListener
This object implements SequenceIterator, so you can loop over each sequence produced. It consumes a stream, and uses a SequenceFormat to extract each sequence from the stream.
It is assumed that the stream contains sequences that can be handled by the one format, and that they are not seperated other than by delimiters that the format can handle.
Sequences are instantiated when they are requested by nextSequence, not before, so it is safe to use this object to parse a gigabyte fasta file, and do sequence-by-sequence processing, while being guaranteed that StreamReader will not require you to keep any of the sequences in memory.
More functionality is offered by RichStreamReader
,
Use of this interface is prefered.
- Author:
- Matthew Pocock, Thomas Down
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStreamReader
(BufferedReader reader, SequenceFormat format, SymbolTokenization symParser, SequenceBuilderFactory sf) StreamReader
(InputStream is, SequenceFormat format, SymbolTokenization symParser, SequenceBuilderFactory sf) -
Method Summary
Modifier and TypeMethodDescriptionvoid
BadLineParsed
(ParseErrorEvent theEvent) This method determines the behaviour when a bad line is processed.boolean
hasNext()
Returns whether there are more sequences to iterate over.Pull the next sequence out of the stream.
-
Constructor Details
-
StreamReader
public StreamReader(InputStream is, SequenceFormat format, SymbolTokenization symParser, SequenceBuilderFactory sf) -
StreamReader
public StreamReader(BufferedReader reader, SequenceFormat format, SymbolTokenization symParser, SequenceBuilderFactory sf)
-
-
Method Details
-
nextSequence
Pull the next sequence out of the stream.This method will delegate parsing from the stream to a SequenceFormat object, and then return the resulting sequence.
- Specified by:
nextSequence
in interfaceSequenceIterator
- Returns:
- the next Sequence
- Throws:
NoSuchElementException
- if the end of the stream has been hitBioException
- if for any reason the next sequence could not be read
-
hasNext
Description copied from interface:SequenceIterator
Returns whether there are more sequences to iterate over.- Specified by:
hasNext
in interfaceSequenceIterator
- Returns:
- true if there are more sequences to get and false otherwise
-
BadLineParsed
This method determines the behaviour when a bad line is processed. Some options are to log the error, throw an exception, ignore it completely, or pass the event through.This method should be overwritten when different behavior is desired.
- Specified by:
BadLineParsed
in interfaceParseErrorListener
- Parameters:
theEvent
- The event that contains the bad line and token.
-