Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.bin

File JalviewLiteURLRetrieve.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

18
45
2
1
153
113
14
0.31
22.5
2
7

Classes

Class Line # Actions
JalviewLiteURLRetrieve 35 45 14
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.bin;
22   
23    import jalview.datamodel.AlignmentI;
24    import jalview.io.AppletFormatAdapter;
25    import jalview.io.DataSourceType;
26    import jalview.io.FileFormat;
27    import jalview.io.FileFormatI;
28    import jalview.io.FileFormats;
29    import jalview.io.FileParse;
30    import jalview.io.IdentifyFile;
31   
32    import java.applet.Applet;
33    import java.io.InputStream;
34   
 
35    public class JalviewLiteURLRetrieve extends Applet
36    {
37   
38    private static final long serialVersionUID = 1L;
39   
40    /**
41    * This is the default constructor
42    */
 
43  0 toggle public JalviewLiteURLRetrieve()
44    {
45  0 super();
46    }
47   
48    /**
49    * This method initializes this
50    *
51    * @return void
52    */
 
53  0 toggle @Override
54    public void init()
55    {
56  0 this.setSize(300, 200);
57  0 String file = getParameter("file");
58  0 if (file == null)
59    {
60  0 System.out
61    .println("Specify a resource to read on the file parameter");
62  0 return;
63    }
64  0 DataSourceType protocol = null;
65  0 try
66    {
67  0 jalview.bin.Console
68    .outPrintln("Loading thread started with:\n>>file\n" + file
69    + ">>endfile");
70    // This might throw a security exception in certain browsers
71    // Netscape Communicator for instance.
72  0 try
73    {
74  0 boolean rtn = false;
75  0 InputStream is = getClass().getResourceAsStream("/" + file);
76  0 if (is != null)
77    {
78  0 rtn = true;
79  0 is.close();
80    }
81  0 jalview.bin.Console.errPrintln("Resource '" + file + "' was "
82  0 + (rtn ? "" : "not") + " located by classloader.");
83  0 if (rtn)
84    {
85  0 protocol = DataSourceType.CLASSLOADER;
86    }
87   
88    } catch (Exception ex)
89    {
90  0 jalview.bin.Console.outPrintln(
91    "Exception checking resources: " + file + " " + ex);
92    }
93  0 if (file.indexOf("://") > -1)
94    {
95  0 protocol = DataSourceType.URL;
96    }
97    else
98    {
99    // skipping codebase prepend check.
100  0 protocol = DataSourceType.FILE;
101    }
102   
103  0 jalview.bin.Console.outPrintln("Trying to get contents of resource:");
104  0 FileParse fp = new FileParse(file, protocol);
105  0 if (fp.isValid())
106    {
107  0 String ln = null;
108  0 while ((ln = fp.nextLine()) != null)
109    {
110  0 System.out.print(ln);
111    }
112  0 fp.close();
113    }
114    else
115    {
116  0 jalview.bin.Console.outPrintln("Resource at " + file
117    + " cannot be read with protocol==" + protocol);
118  0 return;
119    }
120  0 FileFormatI format = FileFormats.getInstance()
121    .forName(getParameter("format"));
122  0 if (format == null)
123    {
124  0 format = new IdentifyFile().identify(file, protocol);
125  0 jalview.bin.Console.outPrintln("Format is " + format);
126    }
127    else
128    {
129  0 jalview.bin.Console
130    .outPrintln("User specified Format is " + format);
131    }
132  0 AlignmentI al = null;
133  0 try
134    {
135  0 al = new AppletFormatAdapter().readFile(file, protocol, format);
136    } catch (java.io.IOException ex)
137    {
138  0 jalview.bin.Console.errPrintln("Failed to open the file.");
139  0 ex.printStackTrace();
140    }
141  0 if (al != null)
142    {
143  0 jalview.bin.Console.outPrintln(new AppletFormatAdapter()
144    .formatSequences(FileFormat.Fasta, al, false));
145    }
146    } catch (Exception e)
147    {
148  0 jalview.bin.Console.errPrintln("bailing out : Unexpected exception:");
149  0 e.printStackTrace();
150    }
151    }
152   
153    }