1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import java.io.BufferedInputStream; |
24 |
|
import java.io.BufferedReader; |
25 |
|
import java.io.ByteArrayInputStream; |
26 |
|
import java.io.File; |
27 |
|
import java.io.FileInputStream; |
28 |
|
import java.io.FileNotFoundException; |
29 |
|
import java.io.FileReader; |
30 |
|
import java.io.IOException; |
31 |
|
import java.io.InputStream; |
32 |
|
import java.io.InputStreamReader; |
33 |
|
import java.io.Reader; |
34 |
|
import java.io.StringReader; |
35 |
|
import java.net.HttpURLConnection; |
36 |
|
import java.net.MalformedURLException; |
37 |
|
import java.net.SocketTimeoutException; |
38 |
|
import java.net.URL; |
39 |
|
import java.net.URLConnection; |
40 |
|
import java.net.UnknownHostException; |
41 |
|
import java.util.zip.GZIPInputStream; |
42 |
|
|
43 |
|
import jalview.api.AlignExportSettingsI; |
44 |
|
import jalview.api.AlignViewportI; |
45 |
|
import jalview.api.AlignmentViewPanel; |
46 |
|
import jalview.api.FeatureSettingsModelI; |
47 |
|
import jalview.bin.Console; |
48 |
|
import jalview.util.HttpUtils; |
49 |
|
import jalview.util.MessageManager; |
50 |
|
import jalview.util.Platform; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 43.7% |
Uncovered Elements: 202 (359) |
Complexity: 101 |
Complexity Density: 0.44 |
|
56 |
|
public class FileParse |
57 |
|
{ |
58 |
|
protected static final String SPACE = " "; |
59 |
|
|
60 |
|
protected static final String TAB = "\t"; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private String dataName = "unknown source"; |
66 |
|
|
67 |
|
public File inFile = null; |
68 |
|
|
69 |
|
private byte[] bytes; |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
public byte[] getBytes()... |
72 |
|
{ |
73 |
0 |
return bytes; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private AlignViewportI viewport; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
private AlignExportSettingsI exportSettings; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
public int index = 1; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
protected char suffixSeparator = '#'; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
protected String newline = System.getProperty("line.separator"); |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
109 |
public void setNewlineString(String nl)... |
104 |
|
{ |
105 |
109 |
newline = nl; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
public String getNewlineString()... |
109 |
|
{ |
110 |
0 |
return newline; |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
protected String suffix = null; |
118 |
|
|
119 |
|
protected DataSourceType dataSourceType = null; |
120 |
|
|
121 |
|
protected BufferedReader dataIn = null; |
122 |
|
|
123 |
|
protected String errormessage = "UNINITIALISED SOURCE"; |
124 |
|
|
125 |
|
protected boolean error = true; |
126 |
|
|
127 |
|
protected String warningMessage = null; |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
final int READAHEAD_LIMIT = 2048; |
133 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
134 |
141 |
public FileParse()... |
135 |
|
{ |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
145 |
462 |
public FileParse(FileParse from) throws IOException... |
146 |
|
{ |
147 |
462 |
if (from == null) |
148 |
|
{ |
149 |
0 |
throw new Error(MessageManager |
150 |
|
.getString("error.implementation_error_null_fileparse")); |
151 |
|
} |
152 |
462 |
if (from == this) |
153 |
|
{ |
154 |
0 |
return; |
155 |
|
} |
156 |
462 |
index = ++from.index; |
157 |
462 |
inFile = from.inFile; |
158 |
462 |
suffixSeparator = from.suffixSeparator; |
159 |
462 |
suffix = from.suffix; |
160 |
462 |
errormessage = from.errormessage; |
161 |
462 |
error = false; |
162 |
462 |
dataSourceType = from.dataSourceType; |
163 |
462 |
dataIn = from.dataIn; |
164 |
462 |
if (dataIn != null) |
165 |
|
{ |
166 |
462 |
mark(); |
167 |
|
} |
168 |
462 |
dataName = from.dataName; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
@return |
177 |
|
|
|
|
| 55.6% |
Uncovered Elements: 12 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
178 |
397 |
private boolean checkFileSource(String fileStr) throws IOException... |
179 |
|
{ |
180 |
397 |
error = false; |
181 |
397 |
this.inFile = new File(fileStr); |
182 |
|
|
183 |
397 |
if (!inFile.exists()) |
184 |
|
{ |
185 |
0 |
errormessage = "FILE NOT FOUND"; |
186 |
0 |
error = true; |
187 |
|
} |
188 |
397 |
if (!inFile.canRead()) |
189 |
|
{ |
190 |
0 |
errormessage = "FILE CANNOT BE OPENED FOR READING"; |
191 |
0 |
error = true; |
192 |
|
} |
193 |
397 |
if (inFile.isDirectory()) |
194 |
|
{ |
195 |
|
|
196 |
|
|
197 |
0 |
errormessage = "FILE IS A DIRECTORY"; |
198 |
0 |
error = true; |
199 |
|
} |
200 |
397 |
if (!error) |
201 |
|
{ |
202 |
397 |
try |
203 |
|
{ |
204 |
397 |
dataIn = checkForGzipStream(new FileInputStream(fileStr)); |
205 |
397 |
dataName = fileStr; |
206 |
|
} catch (Exception x) |
207 |
|
{ |
208 |
0 |
warningMessage = "Failed to resolve " + fileStr |
209 |
|
+ " as a data source. (" + x.getMessage() + ")"; |
210 |
|
|
211 |
0 |
error = true; |
212 |
|
} |
213 |
397 |
; |
214 |
|
} |
215 |
397 |
return error; |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@param |
224 |
|
|
225 |
|
@return |
226 |
|
@throws |
227 |
|
|
|
|
| 66.7% |
Uncovered Elements: 5 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
228 |
397 |
public static boolean isGzipStream(InputStream input) throws IOException... |
229 |
|
{ |
230 |
397 |
if (!input.markSupported()) |
231 |
|
{ |
232 |
0 |
Console.error( |
233 |
|
"FileParse.izGzipStream: input stream must support mark/reset"); |
234 |
0 |
return false; |
235 |
|
} |
236 |
397 |
input.mark(4); |
237 |
|
|
238 |
|
|
239 |
397 |
byte[] bytes = new byte[2]; |
240 |
397 |
int read = input.read(bytes); |
241 |
397 |
input.reset(); |
242 |
397 |
if (read != bytes.length) |
243 |
|
{ |
244 |
0 |
return false; |
245 |
|
} |
246 |
|
|
247 |
397 |
int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); |
248 |
397 |
return (GZIPInputStream.GZIP_MAGIC == header); |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
@param |
256 |
|
@return |
257 |
|
|
|
|
| 72.7% |
Uncovered Elements: 3 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
258 |
397 |
private BufferedReader checkForGzipStream(InputStream input)... |
259 |
|
throws Exception |
260 |
|
{ |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
397 |
if (!input.markSupported()) |
265 |
|
{ |
266 |
397 |
input = new BufferedInputStream(input, 16); |
267 |
|
} |
268 |
397 |
if (isGzipStream(input)) |
269 |
|
{ |
270 |
0 |
return getGzipReader(input); |
271 |
|
} |
272 |
|
|
273 |
397 |
InputStreamReader isReader = new InputStreamReader(input); |
274 |
397 |
BufferedReader toReadFrom = new BufferedReader(isReader); |
275 |
397 |
return toReadFrom; |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
@param |
284 |
|
@return |
285 |
|
@throws |
286 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
287 |
0 |
private BufferedReader getGzipReader(InputStream inputStream)... |
288 |
|
throws Exception |
289 |
|
{ |
290 |
0 |
BufferedReader inData = new BufferedReader( |
291 |
|
new InputStreamReader(new GZIPInputStream(inputStream))); |
292 |
0 |
inData.mark(2048); |
293 |
0 |
inData.read(); |
294 |
0 |
inData.reset(); |
295 |
0 |
return inData; |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
@param |
312 |
|
@throws |
313 |
|
@throws |
314 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 7 |
Complexity Density: 0.24 |
|
315 |
0 |
private void checkURLSource(String urlStr)... |
316 |
|
throws IOException, MalformedURLException |
317 |
|
{ |
318 |
0 |
errormessage = "URL NOT FOUND"; |
319 |
0 |
URL url = new URL(urlStr); |
320 |
0 |
URLConnection _conn = HttpUtils.openConnection(url); |
321 |
0 |
if (_conn instanceof HttpURLConnection) |
322 |
|
{ |
323 |
0 |
HttpURLConnection conn = HttpUtils |
324 |
|
.followConnection((HttpURLConnection) _conn); |
325 |
0 |
int rc = conn.getResponseCode(); |
326 |
0 |
if (rc != HttpURLConnection.HTTP_OK) |
327 |
|
{ |
328 |
0 |
throw new FileNotFoundException("Response status from " + urlStr |
329 |
|
+ " was " + conn.getResponseCode()); |
330 |
|
} |
331 |
0 |
_conn = conn; |
332 |
|
} |
333 |
|
else |
334 |
|
{ |
335 |
0 |
try |
336 |
|
{ |
337 |
0 |
dataIn = checkForGzipStream(_conn.getInputStream()); |
338 |
0 |
dataName = urlStr; |
339 |
|
} catch (IOException ex) |
340 |
|
{ |
341 |
0 |
throw new IOException("Failed to handle non-HTTP URI stream", ex); |
342 |
|
} catch (Exception ex) |
343 |
|
{ |
344 |
0 |
throw new IOException( |
345 |
|
"Failed to determine type of input stream for given URI", |
346 |
|
ex); |
347 |
|
} |
348 |
0 |
return; |
349 |
|
} |
350 |
0 |
String encoding = _conn.getContentEncoding(); |
351 |
0 |
String contentType = _conn.getContentType(); |
352 |
0 |
boolean isgzipped = "application/x-gzip".equalsIgnoreCase(contentType) |
353 |
|
|| contentType.endsWith("gzip") || "gzip".equals(encoding); |
354 |
0 |
Exception e = null; |
355 |
0 |
InputStream inputStream = _conn.getInputStream(); |
356 |
0 |
if (isgzipped) |
357 |
|
{ |
358 |
0 |
try |
359 |
|
{ |
360 |
0 |
dataIn = getGzipReader(inputStream); |
361 |
0 |
dataName = urlStr; |
362 |
|
} catch (Exception e1) |
363 |
|
{ |
364 |
0 |
throw new IOException(MessageManager |
365 |
|
.getString("exception.failed_to_resolve_gzip_stream"), e); |
366 |
|
} |
367 |
0 |
return; |
368 |
|
} |
369 |
|
|
370 |
0 |
dataIn = new BufferedReader(new InputStreamReader(inputStream)); |
371 |
0 |
dataName = urlStr; |
372 |
0 |
return; |
373 |
|
} |
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
@param |
380 |
|
@return |
381 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
382 |
0 |
private String extractSuffix(String fileStr)... |
383 |
|
{ |
384 |
|
|
385 |
0 |
int sfpos = fileStr.lastIndexOf(suffixSeparator); |
386 |
0 |
if (sfpos > -1 && sfpos < fileStr.length() - 1) |
387 |
|
{ |
388 |
0 |
suffix = fileStr.substring(sfpos + 1); |
389 |
|
|
390 |
0 |
return fileStr.substring(0, sfpos); |
391 |
|
} |
392 |
0 |
return null; |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
399 |
0 |
public FileParse(BufferedReader source, String originString,... |
400 |
|
DataSourceType sourceType) |
401 |
|
{ |
402 |
0 |
dataSourceType = sourceType; |
403 |
0 |
error = false; |
404 |
0 |
inFile = null; |
405 |
0 |
dataName = originString; |
406 |
0 |
dataIn = source; |
407 |
0 |
try |
408 |
|
{ |
409 |
0 |
if (dataIn.markSupported()) |
410 |
|
{ |
411 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
412 |
|
} |
413 |
|
} catch (IOException q) |
414 |
|
{ |
415 |
|
|
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
@param |
424 |
|
|
425 |
|
@param |
426 |
|
|
427 |
|
@throws |
428 |
|
@throws |
429 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
430 |
754 |
public FileParse(Object file, DataSourceType sourceType)... |
431 |
|
throws MalformedURLException, FileNotFoundException, IOException |
432 |
|
{ |
433 |
754 |
if (file instanceof File) |
434 |
|
{ |
435 |
14 |
parse((File) file, ((File) file).getPath(), sourceType, true); |
436 |
|
} |
437 |
|
else |
438 |
|
{ |
439 |
740 |
parse(null, file.toString(), sourceType, false); |
440 |
|
} |
441 |
|
} |
442 |
|
|
|
|
| 35% |
Uncovered Elements: 65 (100) |
Complexity: 28 |
Complexity Density: 0.45 |
|
443 |
754 |
private void parse(File file, String fileStr, DataSourceType sourceType,... |
444 |
|
boolean isFileObject) throws FileNotFoundException, IOException |
445 |
|
{ |
446 |
754 |
bytes = Platform.getFileBytes(file); |
447 |
754 |
dataSourceType = sourceType; |
448 |
754 |
error = false; |
449 |
754 |
boolean filenotfound = false; |
450 |
|
|
451 |
754 |
if (sourceType == DataSourceType.FILE) |
452 |
|
{ |
453 |
|
|
454 |
397 |
if (bytes != null) |
455 |
|
{ |
456 |
|
|
457 |
0 |
inFile = file; |
458 |
0 |
dataIn = new BufferedReader( |
459 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
460 |
0 |
dataName = fileStr; |
461 |
|
} |
462 |
397 |
else if (checkFileSource(fileStr)) |
463 |
|
{ |
464 |
0 |
String suffixLess = extractSuffix(fileStr); |
465 |
0 |
if (suffixLess != null) |
466 |
|
{ |
467 |
0 |
if (checkFileSource(suffixLess)) |
468 |
|
{ |
469 |
0 |
throw new IOException(MessageManager.formatMessage( |
470 |
|
"exception.problem_opening_file_also_tried", |
471 |
|
new String[] |
472 |
|
{ inFile.getName(), suffixLess, errormessage })); |
473 |
|
} |
474 |
|
} |
475 |
|
else |
476 |
|
{ |
477 |
0 |
throw new IOException(MessageManager.formatMessage( |
478 |
|
"exception.problem_opening_file", new String[] |
479 |
|
{ inFile.getName(), errormessage })); |
480 |
|
} |
481 |
|
} |
482 |
|
} |
483 |
357 |
else if (sourceType == DataSourceType.RELATIVE_URL) |
484 |
|
{ |
485 |
|
|
486 |
0 |
bytes = Platform.getFileAsBytes(fileStr); |
487 |
0 |
dataIn = new BufferedReader( |
488 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
489 |
0 |
dataName = fileStr; |
490 |
|
|
491 |
|
} |
492 |
357 |
else if (sourceType == DataSourceType.URL) |
493 |
|
{ |
494 |
0 |
try |
495 |
|
{ |
496 |
0 |
try |
497 |
|
{ |
498 |
0 |
checkURLSource(fileStr); |
499 |
0 |
if (suffixSeparator == '#') |
500 |
|
{ |
501 |
0 |
extractSuffix(fileStr); |
502 |
|
} |
503 |
|
} catch (IOException e) |
504 |
|
{ |
505 |
0 |
String suffixLess = extractSuffix(fileStr); |
506 |
0 |
if (suffixLess == null) |
507 |
|
{ |
508 |
0 |
if (e instanceof FileNotFoundException |
509 |
|
|| e instanceof UnknownHostException |
510 |
|
|| e instanceof SocketTimeoutException) |
511 |
|
{ |
512 |
0 |
errormessage = "File at URL '" + fileStr + "' not found"; |
513 |
0 |
filenotfound = true; |
514 |
|
} |
515 |
0 |
throw (e); |
516 |
|
} |
517 |
|
else |
518 |
|
{ |
519 |
0 |
try |
520 |
|
{ |
521 |
0 |
checkURLSource(suffixLess); |
522 |
|
} catch (IOException e2) |
523 |
|
{ |
524 |
0 |
errormessage = "BAD URL WITH OR WITHOUT SUFFIX '" + fileStr |
525 |
|
+ "'"; |
526 |
0 |
if (e instanceof FileNotFoundException |
527 |
|
|| e instanceof UnknownHostException |
528 |
|
|| e instanceof SocketTimeoutException) |
529 |
|
{ |
530 |
0 |
filenotfound = true; |
531 |
|
} |
532 |
0 |
throw (e); |
533 |
|
} |
534 |
|
} |
535 |
|
} |
536 |
|
} catch (Exception e) |
537 |
|
{ |
538 |
0 |
errormessage = "CANNOT ACCESS DATA AT URL '" + fileStr + "' (" |
539 |
|
+ e.getMessage() + ")"; |
540 |
0 |
error = true; |
541 |
|
} |
542 |
|
} |
543 |
357 |
else if (sourceType == DataSourceType.PASTE) |
544 |
|
{ |
545 |
252 |
errormessage = "PASTE INACCESSIBLE!"; |
546 |
252 |
dataIn = new BufferedReader(new StringReader(fileStr)); |
547 |
252 |
dataName = "Paste"; |
548 |
|
} |
549 |
105 |
else if (sourceType == DataSourceType.CLASSLOADER) |
550 |
|
{ |
551 |
105 |
errormessage = "RESOURCE CANNOT BE LOCATED"; |
552 |
105 |
InputStream is = getClass().getResourceAsStream("/" + fileStr); |
553 |
105 |
if (is == null) |
554 |
|
{ |
555 |
0 |
String suffixLess = extractSuffix(fileStr); |
556 |
0 |
if (suffixLess != null) |
557 |
|
{ |
558 |
0 |
is = getClass().getResourceAsStream("/" + suffixLess); |
559 |
|
} |
560 |
|
} |
561 |
105 |
if (is != null) |
562 |
|
{ |
563 |
105 |
dataIn = new BufferedReader(new InputStreamReader(is)); |
564 |
105 |
dataName = fileStr; |
565 |
|
} |
566 |
|
else |
567 |
|
{ |
568 |
0 |
error = true; |
569 |
|
} |
570 |
|
} |
571 |
|
else |
572 |
|
{ |
573 |
0 |
errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" |
574 |
0 |
+ (sourceType != null ? sourceType : "null") + "'"; |
575 |
0 |
error = true; |
576 |
|
} |
577 |
754 |
if (dataIn == null || error) |
578 |
|
{ |
579 |
|
|
580 |
0 |
if (filenotfound) |
581 |
|
{ |
582 |
0 |
throw new FileNotFoundException(MessageManager |
583 |
|
.formatMessage("label.url_not_found", new String[] |
584 |
|
{ errormessage })); |
585 |
|
} |
586 |
0 |
throw new IOException(MessageManager.formatMessage( |
587 |
|
"exception.failed_to_read_data_from_source", new String[] |
588 |
|
{ errormessage })); |
589 |
|
} |
590 |
754 |
error = false; |
591 |
754 |
dataIn.mark(READAHEAD_LIMIT); |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
@throws |
599 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
600 |
462 |
public void mark() throws IOException... |
601 |
|
{ |
602 |
462 |
if (dataIn != null) |
603 |
|
{ |
604 |
462 |
dataIn.mark(READAHEAD_LIMIT); |
605 |
|
} |
606 |
|
else |
607 |
|
{ |
608 |
0 |
throw new IOException( |
609 |
|
MessageManager.getString("exception.no_init_source_stream")); |
610 |
|
} |
611 |
|
} |
612 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
613 |
65011 |
public String nextLine() throws IOException... |
614 |
|
{ |
615 |
65011 |
if (!error) |
616 |
|
{ |
617 |
65011 |
return dataIn.readLine(); |
618 |
|
} |
619 |
0 |
throw new IOException(MessageManager |
620 |
|
.formatMessage("exception.invalid_source_stream", new String[] |
621 |
|
{ errormessage })); |
622 |
|
} |
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
@return |
627 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
628 |
0 |
public boolean isExporting()... |
629 |
|
{ |
630 |
0 |
return !error && dataIn == null; |
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
@return |
636 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
637 |
231 |
public boolean isValid()... |
638 |
|
{ |
639 |
231 |
return !error; |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
645 |
219 |
public void close() throws IOException... |
646 |
|
{ |
647 |
219 |
errormessage = "EXCEPTION ON CLOSE"; |
648 |
219 |
error = true; |
649 |
219 |
dataIn.close(); |
650 |
219 |
dataIn = null; |
651 |
219 |
errormessage = "SOURCE IS CLOSED"; |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
@param |
658 |
|
|
659 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
660 |
0 |
public void reset(int bytesRead) throws IOException... |
661 |
|
{ |
662 |
0 |
if (bytesRead >= READAHEAD_LIMIT) |
663 |
|
{ |
664 |
0 |
jalview.bin.Console.errPrintln(String.format( |
665 |
|
"File reset error: read %d bytes but reset limit is %d", |
666 |
|
bytesRead, READAHEAD_LIMIT)); |
667 |
|
} |
668 |
0 |
if (dataIn != null && !error) |
669 |
|
{ |
670 |
0 |
dataIn.reset(); |
671 |
|
} |
672 |
|
else |
673 |
|
{ |
674 |
0 |
throw new IOException(MessageManager.getString( |
675 |
|
"error.implementation_error_reset_called_for_invalid_source")); |
676 |
|
} |
677 |
|
} |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
@return |
682 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
683 |
112 |
public boolean hasWarningMessage()... |
684 |
|
{ |
685 |
112 |
return (warningMessage != null && warningMessage.length() > 0); |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
@return |
691 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
692 |
9 |
public String getWarningMessage()... |
693 |
|
{ |
694 |
9 |
return warningMessage; |
695 |
|
} |
696 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
697 |
32 |
public String getInFile()... |
698 |
|
{ |
699 |
32 |
if (inFile != null) |
700 |
|
{ |
701 |
16 |
return inFile.getAbsolutePath() + " (" + index + ")"; |
702 |
|
} |
703 |
|
else |
704 |
|
{ |
705 |
16 |
return "From Paste + (" + index + ")"; |
706 |
|
} |
707 |
|
} |
708 |
|
|
709 |
|
|
710 |
|
@return |
711 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
712 |
193 |
public String getDataName()... |
713 |
|
{ |
714 |
193 |
return dataName; |
715 |
|
} |
716 |
|
|
717 |
|
|
718 |
|
|
719 |
|
|
720 |
|
@param |
721 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
722 |
0 |
protected void setDataName(String dataname)... |
723 |
|
{ |
724 |
0 |
dataName = dataname; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
@return |
731 |
|
@throws |
732 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
733 |
58 |
public Reader getReader()... |
734 |
|
{ |
735 |
58 |
if (dataIn != null) |
736 |
|
|
737 |
|
{ |
738 |
58 |
return dataIn; |
739 |
|
} |
740 |
0 |
return null; |
741 |
|
} |
742 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
743 |
12 |
public AlignViewportI getViewport()... |
744 |
|
{ |
745 |
12 |
return viewport; |
746 |
|
} |
747 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
748 |
60 |
public void setViewport(AlignViewportI viewport)... |
749 |
|
{ |
750 |
60 |
this.viewport = viewport; |
751 |
|
} |
752 |
|
|
753 |
|
|
754 |
|
@return |
755 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
756 |
4 |
public AlignExportSettingsI getExportSettings()... |
757 |
|
{ |
758 |
4 |
return exportSettings; |
759 |
|
} |
760 |
|
|
761 |
|
|
762 |
|
|
763 |
|
|
764 |
|
@param |
765 |
|
|
766 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
767 |
109 |
public void setExportSettings(AlignExportSettingsI exportSettings)... |
768 |
|
{ |
769 |
109 |
this.exportSettings = exportSettings; |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
@param |
777 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
778 |
108 |
public void configureForView(AlignmentViewPanel avpanel)... |
779 |
|
{ |
780 |
108 |
if (avpanel != null) |
781 |
|
{ |
782 |
60 |
setViewport(avpanel.getAlignViewport()); |
783 |
|
} |
784 |
|
|
785 |
|
} |
786 |
|
|
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
@return |
792 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
793 |
162 |
public FeatureSettingsModelI getFeatureColourScheme()... |
794 |
|
{ |
795 |
162 |
return null; |
796 |
|
} |
797 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
798 |
0 |
public DataSourceType getDataSourceType()... |
799 |
|
{ |
800 |
0 |
return dataSourceType; |
801 |
|
} |
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
@param |
808 |
|
|
809 |
|
@param |
810 |
|
@return |
811 |
|
@throws |
812 |
|
|
|
|
| 30.6% |
Uncovered Elements: 25 (36) |
Complexity: 10 |
Complexity Density: 0.36 |
|
813 |
9 |
public BufferedReader getBufferedReader(Object file,... |
814 |
|
DataSourceType sourceType) throws IOException |
815 |
|
{ |
816 |
9 |
BufferedReader in = null; |
817 |
9 |
byte[] bytes; |
818 |
|
|
819 |
9 |
switch (sourceType) |
820 |
|
{ |
821 |
1 |
case FILE: |
822 |
1 |
if (file instanceof String) |
823 |
|
{ |
824 |
1 |
return new BufferedReader(new FileReader((String) file)); |
825 |
|
} |
826 |
0 |
bytes = Platform.getFileBytes((File) file); |
827 |
0 |
if (bytes != null) |
828 |
|
{ |
829 |
0 |
return new BufferedReader( |
830 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
831 |
|
} |
832 |
0 |
return new BufferedReader(new FileReader((File) file)); |
833 |
0 |
case URL: |
834 |
0 |
URL url = new URL(file.toString()); |
835 |
0 |
in = new BufferedReader( |
836 |
|
new InputStreamReader(HttpUtils.openStream(url))); |
837 |
0 |
break; |
838 |
0 |
case RELATIVE_URL: |
839 |
0 |
bytes = Platform.getFileAsBytes(file.toString()); |
840 |
0 |
if (bytes != null) |
841 |
|
{ |
842 |
0 |
in = new BufferedReader( |
843 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
844 |
|
} |
845 |
0 |
break; |
846 |
8 |
case PASTE: |
847 |
8 |
in = new BufferedReader(new StringReader(file.toString())); |
848 |
8 |
break; |
849 |
0 |
case CLASSLOADER: |
850 |
0 |
InputStream is = getClass().getResourceAsStream("/" + file); |
851 |
0 |
if (is != null) |
852 |
|
{ |
853 |
0 |
in = new BufferedReader(new InputStreamReader(is)); |
854 |
|
} |
855 |
0 |
break; |
856 |
|
} |
857 |
|
|
858 |
8 |
return in; |
859 |
|
} |
860 |
|
} |