1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 14 |
Complexity Density: 0.31 |
|
35 |
|
public class JalviewLiteURLRetrieve extends Applet |
36 |
|
{ |
37 |
|
|
38 |
|
private static final long serialVersionUID = 1L; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
0 |
public JalviewLiteURLRetrieve()... |
44 |
|
{ |
45 |
0 |
super(); |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@return |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 13 |
Complexity Density: 0.3 |
|
53 |
0 |
@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 |
|
|
71 |
|
|
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 |
|
|
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 |
|
} |