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 |
|
|
|
|
| 0% |
Uncovered Elements: 359 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0 |
public void setNewlineString(String nl)... |
104 |
|
{ |
105 |
0 |
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 |
0 |
public FileParse()... |
135 |
|
{ |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
145 |
0 |
public FileParse(FileParse from) throws IOException... |
146 |
|
{ |
147 |
0 |
if (from == null) |
148 |
|
{ |
149 |
0 |
throw new Error(MessageManager |
150 |
|
.getString("error.implementation_error_null_fileparse")); |
151 |
|
} |
152 |
0 |
if (from == this) |
153 |
|
{ |
154 |
0 |
return; |
155 |
|
} |
156 |
0 |
index = ++from.index; |
157 |
0 |
inFile = from.inFile; |
158 |
0 |
suffixSeparator = from.suffixSeparator; |
159 |
0 |
suffix = from.suffix; |
160 |
0 |
errormessage = from.errormessage; |
161 |
0 |
error = false; |
162 |
0 |
dataSourceType = from.dataSourceType; |
163 |
0 |
dataIn = from.dataIn; |
164 |
0 |
if (dataIn != null) |
165 |
|
{ |
166 |
0 |
mark(); |
167 |
|
} |
168 |
0 |
dataName = from.dataName; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
@return |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
178 |
0 |
private boolean checkFileSource(String fileStr) throws IOException... |
179 |
|
{ |
180 |
0 |
error = false; |
181 |
0 |
this.inFile = new File(fileStr); |
182 |
|
|
183 |
0 |
if (!inFile.exists()) |
184 |
|
{ |
185 |
0 |
errormessage = "FILE NOT FOUND"; |
186 |
0 |
error = true; |
187 |
|
} |
188 |
0 |
if (!inFile.canRead()) |
189 |
|
{ |
190 |
0 |
errormessage = "FILE CANNOT BE OPENED FOR READING"; |
191 |
0 |
error = true; |
192 |
|
} |
193 |
0 |
if (inFile.isDirectory()) |
194 |
|
{ |
195 |
|
|
196 |
|
|
197 |
0 |
errormessage = "FILE IS A DIRECTORY"; |
198 |
0 |
error = true; |
199 |
|
} |
200 |
0 |
if (!error) |
201 |
|
{ |
202 |
0 |
try |
203 |
|
{ |
204 |
0 |
dataIn = checkForGzipStream(new FileInputStream(fileStr)); |
205 |
0 |
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 |
0 |
; |
214 |
|
} |
215 |
0 |
return error; |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@param |
224 |
|
|
225 |
|
@return |
226 |
|
@throws |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
228 |
0 |
public static boolean isGzipStream(InputStream input) throws IOException... |
229 |
|
{ |
230 |
0 |
if (!input.markSupported()) |
231 |
|
{ |
232 |
0 |
Console.error( |
233 |
|
"FileParse.izGzipStream: input stream must support mark/reset"); |
234 |
0 |
return false; |
235 |
|
} |
236 |
0 |
input.mark(4); |
237 |
|
|
238 |
|
|
239 |
0 |
byte[] bytes = new byte[2]; |
240 |
0 |
int read = input.read(bytes); |
241 |
0 |
input.reset(); |
242 |
0 |
if (read != bytes.length) |
243 |
|
{ |
244 |
0 |
return false; |
245 |
|
} |
246 |
|
|
247 |
0 |
int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); |
248 |
0 |
return (GZIPInputStream.GZIP_MAGIC == header); |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
@param |
256 |
|
@return |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
258 |
0 |
private BufferedReader checkForGzipStream(InputStream input)... |
259 |
|
throws Exception |
260 |
|
{ |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
0 |
if (!input.markSupported()) |
265 |
|
{ |
266 |
0 |
input = new BufferedInputStream(input, 16); |
267 |
|
} |
268 |
0 |
if (isGzipStream(input)) |
269 |
|
{ |
270 |
0 |
return getGzipReader(input); |
271 |
|
} |
272 |
|
|
273 |
0 |
InputStreamReader isReader = new InputStreamReader(input); |
274 |
0 |
BufferedReader toReadFrom = new BufferedReader(isReader); |
275 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
430 |
0 |
public FileParse(Object file, DataSourceType sourceType)... |
431 |
|
throws MalformedURLException, FileNotFoundException, IOException |
432 |
|
{ |
433 |
0 |
if (file instanceof File) |
434 |
|
{ |
435 |
0 |
parse((File) file, ((File) file).getPath(), sourceType, true); |
436 |
|
} |
437 |
|
else |
438 |
|
{ |
439 |
0 |
parse(null, file.toString(), sourceType, false); |
440 |
|
} |
441 |
|
} |
442 |
|
|
|
|
| 0% |
Uncovered Elements: 100 (100) |
Complexity: 28 |
Complexity Density: 0.45 |
|
443 |
0 |
private void parse(File file, String fileStr, DataSourceType sourceType,... |
444 |
|
boolean isFileObject) throws FileNotFoundException, IOException |
445 |
|
{ |
446 |
0 |
bytes = Platform.getFileBytes(file); |
447 |
0 |
dataSourceType = sourceType; |
448 |
0 |
error = false; |
449 |
0 |
boolean filenotfound = false; |
450 |
|
|
451 |
0 |
if (sourceType == DataSourceType.FILE) |
452 |
|
{ |
453 |
|
|
454 |
0 |
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 |
0 |
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 |
0 |
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 |
0 |
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 |
0 |
else if (sourceType == DataSourceType.PASTE) |
544 |
|
{ |
545 |
0 |
errormessage = "PASTE INACCESSIBLE!"; |
546 |
0 |
dataIn = new BufferedReader(new StringReader(fileStr)); |
547 |
0 |
dataName = "Paste"; |
548 |
|
} |
549 |
0 |
else if (sourceType == DataSourceType.CLASSLOADER) |
550 |
|
{ |
551 |
0 |
errormessage = "RESOURCE CANNOT BE LOCATED"; |
552 |
0 |
InputStream is = getClass().getResourceAsStream("/" + fileStr); |
553 |
0 |
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 |
0 |
if (is != null) |
562 |
|
{ |
563 |
0 |
dataIn = new BufferedReader(new InputStreamReader(is)); |
564 |
0 |
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 |
0 |
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 |
0 |
error = false; |
591 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
@throws |
599 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
600 |
0 |
public void mark() throws IOException... |
601 |
|
{ |
602 |
0 |
if (dataIn != null) |
603 |
|
{ |
604 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
605 |
|
} |
606 |
|
else |
607 |
|
{ |
608 |
0 |
throw new IOException( |
609 |
|
MessageManager.getString("exception.no_init_source_stream")); |
610 |
|
} |
611 |
|
} |
612 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
613 |
0 |
public String nextLine() throws IOException... |
614 |
|
{ |
615 |
0 |
if (!error) |
616 |
|
{ |
617 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
637 |
0 |
public boolean isValid()... |
638 |
|
{ |
639 |
0 |
return !error; |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
645 |
0 |
public void close() throws IOException... |
646 |
|
{ |
647 |
0 |
errormessage = "EXCEPTION ON CLOSE"; |
648 |
0 |
error = true; |
649 |
0 |
dataIn.close(); |
650 |
0 |
dataIn = null; |
651 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
683 |
0 |
public boolean hasWarningMessage()... |
684 |
|
{ |
685 |
0 |
return (warningMessage != null && warningMessage.length() > 0); |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
@return |
691 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
692 |
0 |
public String getWarningMessage()... |
693 |
|
{ |
694 |
0 |
return warningMessage; |
695 |
|
} |
696 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
697 |
0 |
public String getInFile()... |
698 |
|
{ |
699 |
0 |
if (inFile != null) |
700 |
|
{ |
701 |
0 |
return inFile.getAbsolutePath() + " (" + index + ")"; |
702 |
|
} |
703 |
|
else |
704 |
|
{ |
705 |
0 |
return "From Paste + (" + index + ")"; |
706 |
|
} |
707 |
|
} |
708 |
|
|
709 |
|
|
710 |
|
@return |
711 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
712 |
0 |
public String getDataName()... |
713 |
|
{ |
714 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
733 |
0 |
public Reader getReader()... |
734 |
|
{ |
735 |
0 |
if (dataIn != null) |
736 |
|
|
737 |
|
{ |
738 |
0 |
return dataIn; |
739 |
|
} |
740 |
0 |
return null; |
741 |
|
} |
742 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
743 |
0 |
public AlignViewportI getViewport()... |
744 |
|
{ |
745 |
0 |
return viewport; |
746 |
|
} |
747 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
748 |
0 |
public void setViewport(AlignViewportI viewport)... |
749 |
|
{ |
750 |
0 |
this.viewport = viewport; |
751 |
|
} |
752 |
|
|
753 |
|
|
754 |
|
@return |
755 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
756 |
0 |
public AlignExportSettingsI getExportSettings()... |
757 |
|
{ |
758 |
0 |
return exportSettings; |
759 |
|
} |
760 |
|
|
761 |
|
|
762 |
|
|
763 |
|
|
764 |
|
@param |
765 |
|
|
766 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
767 |
0 |
public void setExportSettings(AlignExportSettingsI exportSettings)... |
768 |
|
{ |
769 |
0 |
this.exportSettings = exportSettings; |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
@param |
777 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
778 |
0 |
public void configureForView(AlignmentViewPanel avpanel)... |
779 |
|
{ |
780 |
0 |
if (avpanel != null) |
781 |
|
{ |
782 |
0 |
setViewport(avpanel.getAlignViewport()); |
783 |
|
} |
784 |
|
|
785 |
|
} |
786 |
|
|
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
@return |
792 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
793 |
0 |
public FeatureSettingsModelI getFeatureColourScheme()... |
794 |
|
{ |
795 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 10 |
Complexity Density: 0.36 |
|
813 |
0 |
public BufferedReader getBufferedReader(Object file,... |
814 |
|
DataSourceType sourceType) throws IOException |
815 |
|
{ |
816 |
0 |
BufferedReader in = null; |
817 |
0 |
byte[] bytes; |
818 |
|
|
819 |
0 |
switch (sourceType) |
820 |
|
{ |
821 |
0 |
case FILE: |
822 |
0 |
if (file instanceof String) |
823 |
|
{ |
824 |
0 |
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 |
0 |
case PASTE: |
847 |
0 |
in = new BufferedReader(new StringReader(file.toString())); |
848 |
0 |
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 |
0 |
return in; |
859 |
|
} |
860 |
|
} |