org.biojava.bio.seq.io
Class StreamReader

java.lang.Object
  |
  +--org.biojava.bio.seq.io.StreamReader

public class StreamReader
extends java.lang.Object
implements SequenceIterator

Parses a stream into sequences.

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 giggabite 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.

Author:
Matthew Pocock

Inner Class Summary
static class StreamReader.Context
          Encapsulate a stream for reading sequence data.
 
Constructor Summary
StreamReader(java.io.BufferedReader reader, SequenceFormat format, SymbolParser resParser, SequenceFactory sf)
           
StreamReader(java.io.InputStream is, SequenceFormat format, SymbolParser resParser, SequenceFactory sf)
           
 
Method Summary
 boolean hasNext()
          Returns whether there are more sequences to iterate over.
 Sequence nextSequence()
          Pull the next sequence out of the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamReader

public StreamReader(java.io.InputStream is,
                    SequenceFormat format,
                    SymbolParser resParser,
                    SequenceFactory sf)

StreamReader

public StreamReader(java.io.BufferedReader reader,
                    SequenceFormat format,
                    SymbolParser resParser,
                    SequenceFactory sf)
Method Detail

nextSequence

public Sequence nextSequence()
                      throws java.util.NoSuchElementException,
                             BioException
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 interface SequenceIterator
Returns:
the next Sequence
Throws:
java.util.NoSuchElementException - if the end of the stream has been hit
BioException - if for any reason the next sequence could not be read

hasNext

public boolean hasNext()
Description copied from interface: SequenceIterator
Returns whether there are more sequences to iterate over.
Specified by:
hasNext in interface SequenceIterator
Tags copied from interface: SequenceIterator
Returns:
true if there are more sequences to get and false otherwise