2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.InputStream;
27 public class JalviewLiteURLRetrieve extends Applet
30 private static final long serialVersionUID = 1L;
33 * This is the default constructor
35 public JalviewLiteURLRetrieve()
41 * This method initializes this
47 this.setSize(300, 200);
48 String file = getParameter("file");
52 .println("Specify a resource to read on the file parameter");
55 String protocol = null;
58 System.out.println("Loading thread started with:\n>>file\n" + file
60 // This might throw a security exception in certain browsers
61 // Netscape Communicator for instance.
65 InputStream is = getClass().getResourceAsStream("/" + file);
71 System.err.println("Resource '" + file + "' was "
72 + (rtn ? "" : "not") + " located by classloader.");
75 protocol = AppletFormatAdapter.CLASSLOADER;
78 } catch (Exception ex)
80 System.out.println("Exception checking resources: " + file + " "
83 if (file.indexOf("://") > -1)
85 protocol = AppletFormatAdapter.URL;
89 // skipping codebase prepend check.
90 protocol = AppletFormatAdapter.FILE;
93 System.out.println("Trying to get contents of resource:");
94 FileParse fp = new FileParse(file, protocol);
98 while ((ln = fp.nextLine()) != null)
100 System.out.print(ln);
106 System.out.println("Resource at " + file
107 + " cannot be read with protocol==" + protocol);
110 String format = getParameter("format");
111 if (format == null || format.length() == 0)
113 format = new jalview.io.IdentifyFile().Identify(file, protocol);
114 System.out.println("Format is " + format);
118 System.out.println("User specified Format is " + format);
123 al = new AppletFormatAdapter().readFile(file, protocol, format);
124 } catch (java.io.IOException ex)
126 System.err.println("Failed to open the file.");
127 ex.printStackTrace();
131 System.out.println(new AppletFormatAdapter().formatSequences(
132 "FASTA", al, false));
134 } catch (Exception e)
136 System.err.println("bailing out : Unexpected exception:");