- /**
- * This sets the source to be parsed. The source can be: String,
- * StringBuffer, char[], File, or InputStream. The source can contain more
- * than one phylogenies in either New Hamphshire (NH) or New Hamphshire
- * Extended (NHX) format. There is no need to separate phylogenies with any
- * special character. White space is always ignored, as are semicolons
- * inbetween phylogenies. Example of a source describing two phylogenies
- * (source is a String, in this example): "(A,(B,(C,(D,E)de)cde)bcde)abcde
- * ((((A,B)ab,C)abc,D)abcd,E)abcde". Everything between a '[' followed by any
- * character other than '&' and ']' is considered a comment and ignored
- * (example: "[this is a comment]"). NHX tags are surrounded by '[&&NHX' and
- * ']' (example: "[&&NHX:S=Varanus_storri]"). A sequence like "[& some
- * info]" is ignored, too (at the PhylogenyNode level, though).
- * Exception: numbers only between [ and ] (e.g. [90]) are interpreted as support values.
- *
- * @see #parse()
- * @see org.forester.io.parsers.PhylogenyParser#setSource(java.lang.Object)
- * @param nhx_source
- * the source to be parsed (String, StringBuffer, char[], File,
- * or InputStream)
- * @throws IOException
- * @throws PhylogenyParserException
- */
- @Override
- public void setSource( final Object nhx_source ) throws PhylogenyParserException, IOException {
- if ( nhx_source == null ) {
- throw new PhylogenyParserException( getClass() + ": attempt to parse null object." );
- }
- else if ( nhx_source instanceof String ) {
- setInputType( NHXParser.STRING );
- setSourceLength( ( ( String ) nhx_source ).length() );
- setNhxSource( nhx_source );
- }
- else if ( nhx_source instanceof StringBuffer ) {
- setInputType( NHXParser.STRING_BUFFER );
- setSourceLength( ( ( StringBuffer ) nhx_source ).length() );
- setNhxSource( nhx_source );
- }
- else if ( nhx_source instanceof char[] ) {
- setInputType( NHXParser.CHAR_ARRAY );
- setSourceLength( ( ( char[] ) nhx_source ).length );
- setNhxSource( nhx_source );
- }
- else if ( nhx_source instanceof File ) {
- setInputType( NHXParser.BUFFERED_READER );
- setSourceLength( 0 );
- final File f = ( File ) nhx_source;
- final String error = ForesterUtil.isReadableFile( f );
- if ( !ForesterUtil.isEmpty( error ) ) {
- throw new PhylogenyParserException( error );
- }
- setNhxSource( new BufferedReader( new FileReader( f ) ) );