2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.datamodel.Alignment;
21 import jalview.io.AppletFormatAdapter;
22 import jalview.io.FileParse;
24 import java.applet.Applet;
25 import java.io.BufferedInputStream;
26 import java.io.BufferedReader;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
30 public class JalviewLiteURLRetrieve extends Applet
33 private static final long serialVersionUID = 1L;
36 * This is the default constructor
38 public JalviewLiteURLRetrieve()
44 * This method initializes this
50 this.setSize(300, 200);
51 String file = getParameter("file");
55 .println("Specify a resource to read on the file parameter");
58 String protocol = null;
61 System.out.println("Loading thread started with:\n>>file\n" + file
63 // This might throw a security exception in certain browsers
64 // Netscape Communicator for instance.
68 InputStream is = getClass().getResourceAsStream("/" + file);
74 System.err.println("Resource '" + file + "' was "
75 + (rtn ? "" : "not") + " located by classloader.");
78 protocol = AppletFormatAdapter.CLASSLOADER;
81 } catch (Exception ex)
83 System.out.println("Exception checking resources: " + file + " "
86 if (file.indexOf("://") > -1)
88 protocol = AppletFormatAdapter.URL;
92 // skipping codebase prepend check.
93 protocol = AppletFormatAdapter.FILE;
96 System.out.println("Trying to get contents of resource:");
97 FileParse fp = new FileParse(file, protocol);
101 while ((ln = fp.nextLine()) != null)
103 System.out.print(ln);
109 System.out.println("Resource at " + file
110 + " cannot be read with protocol==" + protocol);
113 String format = getParameter("format");
114 if (format == null || format.length() == 0)
116 format = new jalview.io.IdentifyFile().Identify(file, protocol);
117 System.out.println("Format is " + format);
121 System.out.println("User specified Format is " + format);
126 al = new AppletFormatAdapter().readFile(file, protocol, format);
127 } catch (java.io.IOException ex)
129 System.err.println("Failed to open the file.");
130 ex.printStackTrace();
134 System.out.println(new AppletFormatAdapter().formatSequences(
135 "FASTA", al, false));
137 } catch (Exception e)
139 System.err.println("bailing out : Unexpected exception:");