001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.bio.seq.io; 022 023import java.io.IOException; 024 025import org.biojava.bio.symbol.Alphabet; 026import org.biojava.bio.symbol.IllegalSymbolException; 027import org.biojava.bio.symbol.Symbol; 028 029/** 030 * Encapsulate a stream of Symbols being parsed from some input 031 * stream. This allows SymbolList creation to be fully decoupled from 032 * stream parsing. 033 * 034 * @author Thomas Down 035 * @since 1.1 [newio proposal] 036 */ 037 038public interface SymbolReader { 039 /** 040 * Find the alphabet of all symbols which may be returned by 041 * this SymbolReader. <strong>NOTE:</strong> SymbolList 042 * implementations are expected to perform any necessary 043 * validation of returned Symbols. Client code should 044 * not need to perform any extra validation. 045 */ 046 047 public Alphabet getAlphabet(); 048 049 /** 050 * Return a single symbol from the stream. 051 * 052 * @throws IOException if an error occured on the stream, or the 053 * end of the stream has already been reached. 054 * @throws IllegalSymbolException if a parse error occured. 055 */ 056 057 public Symbol readSymbol() throws IOException, IllegalSymbolException; 058 059 /** 060 * Read one or more symbols from the stream. 061 * 062 * @param buffer the destination for read symbols. 063 * @param start a start offset within the buffer. 064 * @param length the maximum number of Symbols to read. 065 * 066 * @return the number of Symbols which were actually read. 067 * 068 * @throws IOException if an error occured on the stream, or the 069 * end of the stream has already been reached. 070 * @throws IllegalSymbolException if a parse error occured. 071 */ 072 073 public int readSymbols(Symbol[] buffer, 074 int start, 075 int length) 076 throws IOException, IllegalSymbolException; 077 078 /** 079 * Determine if there are more symbols left to read in this stream. 080 */ 081 082 public boolean hasMoreSymbols(); 083}