- /**
- * Helper method for calcColor methods.
- *
- *
- * @param value
- * the value
- * @param larger
- * the largest value
- * @param smaller
- * the smallest value
- * @return a normalized value between larger and smaller
- */
- final private static double calculateColorFactor( final double value, final double larger, final double smaller ) {
- return ( 255.0 * ( value - smaller ) ) / ( larger - smaller );
+ public final static Phylogeny[] readPhylogeniesFromUrl( final URL url,
+ final PhylogenyParser parser )
+ throws NoSuchAlgorithmException, IOException, KeyManagementException {
+ if ( url == null ) {
+ throw new IllegalArgumentException( "URL to read from must not be null" );
+ }
+ else if ( parser == null ) {
+ throw new IllegalArgumentException( "parser to use to read from URL must not be null" );
+ }
+ final URLConnection con;
+ if ( url.toString().startsWith( "https:" ) ) {
+ con = TrustManager.makeHttpsURLConnection( url );
+ }
+ else if ( url.toString().startsWith( "http:" ) ) {
+ con = url.openConnection();
+ }
+ else {
+ throw new IllegalArgumentException( "Cannot deal with URL: " + url );
+ }
+ if ( con == null ) {
+ throw new IOException( "could not create connection from " + url );
+ }
+ con.setDefaultUseCaches( false );
+ final InputStream is = con.getInputStream();
+ if ( is == null ) {
+ throw new IOException( "could not create input stream from " + url );
+ }
+ final Phylogeny[] trees = ParserBasedPhylogenyFactory.getInstance().create( is, parser );
+ try {
+ is.close();
+ }
+ catch ( final Exception e ) {
+ // ignore
+ }
+ return trees;