| 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: 361 (361) |
Complexity: 101 |
Complexity Density: 0.43 |
|
| 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: 37 (37) |
Complexity: 7 |
Complexity Density: 0.23 |
|
| 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 = false; |
| 353 |
0 |
isgzipped |=(contentType!=null && ("application/x-gzip".equalsIgnoreCase(contentType) || contentType.endsWith("gzip"))); |
| 354 |
|
|
| 355 |
0 |
isgzipped |= (encoding!=null && "gzip".equals(encoding)); |
| 356 |
|
|
| 357 |
0 |
Exception e = null; |
| 358 |
|
|
| 359 |
0 |
InputStream inputStream = _conn.getInputStream(); |
| 360 |
0 |
if (isgzipped) |
| 361 |
|
{ |
| 362 |
0 |
try |
| 363 |
|
{ |
| 364 |
0 |
dataIn = getGzipReader(inputStream); |
| 365 |
0 |
dataName = urlStr; |
| 366 |
|
} catch (Exception e1) |
| 367 |
|
{ |
| 368 |
0 |
throw new IOException(MessageManager |
| 369 |
|
.getString("exception.failed_to_resolve_gzip_stream"), e); |
| 370 |
|
} |
| 371 |
0 |
return; |
| 372 |
|
} |
| 373 |
|
|
| 374 |
0 |
dataIn = new BufferedReader(new InputStreamReader(inputStream)); |
| 375 |
0 |
dataName = urlStr; |
| 376 |
0 |
return; |
| 377 |
|
} |
| 378 |
|
|
| 379 |
|
|
| 380 |
|
|
| 381 |
|
|
| 382 |
|
|
| 383 |
|
@param |
| 384 |
|
@return |
| 385 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 386 |
0 |
private String extractSuffix(String fileStr)... |
| 387 |
|
{ |
| 388 |
|
|
| 389 |
0 |
int sfpos = fileStr.lastIndexOf(suffixSeparator); |
| 390 |
0 |
if (sfpos > -1 && sfpos < fileStr.length() - 1) |
| 391 |
|
{ |
| 392 |
0 |
suffix = fileStr.substring(sfpos + 1); |
| 393 |
|
|
| 394 |
0 |
return fileStr.substring(0, sfpos); |
| 395 |
|
} |
| 396 |
0 |
return null; |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
|
|
| 401 |
|
|
| 402 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 403 |
0 |
public FileParse(BufferedReader source, String originString,... |
| 404 |
|
DataSourceType sourceType) |
| 405 |
|
{ |
| 406 |
0 |
dataSourceType = sourceType; |
| 407 |
0 |
error = false; |
| 408 |
0 |
inFile = null; |
| 409 |
0 |
dataName = originString; |
| 410 |
0 |
dataIn = source; |
| 411 |
0 |
try |
| 412 |
|
{ |
| 413 |
0 |
if (dataIn.markSupported()) |
| 414 |
|
{ |
| 415 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
| 416 |
|
} |
| 417 |
|
} catch (IOException q) |
| 418 |
|
{ |
| 419 |
|
|
| 420 |
|
} |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
|
| 424 |
|
|
| 425 |
|
|
| 426 |
|
|
| 427 |
|
@param |
| 428 |
|
|
| 429 |
|
@param |
| 430 |
|
|
| 431 |
|
@throws |
| 432 |
|
@throws |
| 433 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 434 |
0 |
public FileParse(Object file, DataSourceType sourceType)... |
| 435 |
|
throws MalformedURLException, FileNotFoundException, IOException |
| 436 |
|
{ |
| 437 |
0 |
if (file instanceof File) |
| 438 |
|
{ |
| 439 |
0 |
parse((File) file, ((File) file).getPath(), sourceType, true); |
| 440 |
|
} |
| 441 |
|
else |
| 442 |
|
{ |
| 443 |
0 |
parse(null, file.toString(), sourceType, false); |
| 444 |
|
} |
| 445 |
|
} |
| 446 |
|
|
| |
|
| 0% |
Uncovered Elements: 100 (100) |
Complexity: 28 |
Complexity Density: 0.45 |
|
| 447 |
0 |
private void parse(File file, String fileStr, DataSourceType sourceType,... |
| 448 |
|
boolean isFileObject) throws FileNotFoundException, IOException |
| 449 |
|
{ |
| 450 |
0 |
bytes = Platform.getFileBytes(file); |
| 451 |
0 |
dataSourceType = sourceType; |
| 452 |
0 |
error = false; |
| 453 |
0 |
boolean filenotfound = false; |
| 454 |
|
|
| 455 |
0 |
if (sourceType == DataSourceType.FILE) |
| 456 |
|
{ |
| 457 |
|
|
| 458 |
0 |
if (bytes != null) |
| 459 |
|
{ |
| 460 |
|
|
| 461 |
0 |
inFile = file; |
| 462 |
0 |
dataIn = new BufferedReader( |
| 463 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
| 464 |
0 |
dataName = fileStr; |
| 465 |
|
} |
| 466 |
0 |
else if (checkFileSource(fileStr)) |
| 467 |
|
{ |
| 468 |
0 |
String suffixLess = extractSuffix(fileStr); |
| 469 |
0 |
if (suffixLess != null) |
| 470 |
|
{ |
| 471 |
0 |
if (checkFileSource(suffixLess)) |
| 472 |
|
{ |
| 473 |
0 |
throw new IOException(MessageManager.formatMessage( |
| 474 |
|
"exception.problem_opening_file_also_tried", |
| 475 |
|
new String[] |
| 476 |
|
{ inFile.getName(), suffixLess, errormessage })); |
| 477 |
|
} |
| 478 |
|
} |
| 479 |
|
else |
| 480 |
|
{ |
| 481 |
0 |
throw new IOException(MessageManager.formatMessage( |
| 482 |
|
"exception.problem_opening_file", new String[] |
| 483 |
|
{ inFile.getName(), errormessage })); |
| 484 |
|
} |
| 485 |
|
} |
| 486 |
|
} |
| 487 |
0 |
else if (sourceType == DataSourceType.RELATIVE_URL) |
| 488 |
|
{ |
| 489 |
|
|
| 490 |
0 |
bytes = Platform.getFileAsBytes(fileStr); |
| 491 |
0 |
dataIn = new BufferedReader( |
| 492 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
| 493 |
0 |
dataName = fileStr; |
| 494 |
|
|
| 495 |
|
} |
| 496 |
0 |
else if (sourceType == DataSourceType.URL) |
| 497 |
|
{ |
| 498 |
0 |
try |
| 499 |
|
{ |
| 500 |
0 |
try |
| 501 |
|
{ |
| 502 |
0 |
checkURLSource(fileStr); |
| 503 |
0 |
if (suffixSeparator == '#') |
| 504 |
|
{ |
| 505 |
0 |
extractSuffix(fileStr); |
| 506 |
|
} |
| 507 |
|
} catch (IOException e) |
| 508 |
|
{ |
| 509 |
0 |
String suffixLess = extractSuffix(fileStr); |
| 510 |
0 |
if (suffixLess == null) |
| 511 |
|
{ |
| 512 |
0 |
if (e instanceof FileNotFoundException |
| 513 |
|
|| e instanceof UnknownHostException |
| 514 |
|
|| e instanceof SocketTimeoutException) |
| 515 |
|
{ |
| 516 |
0 |
errormessage = "File at URL '" + fileStr + "' not found"; |
| 517 |
0 |
filenotfound = true; |
| 518 |
|
} |
| 519 |
0 |
throw (e); |
| 520 |
|
} |
| 521 |
|
else |
| 522 |
|
{ |
| 523 |
0 |
try |
| 524 |
|
{ |
| 525 |
0 |
checkURLSource(suffixLess); |
| 526 |
|
} catch (IOException e2) |
| 527 |
|
{ |
| 528 |
0 |
errormessage = "BAD URL WITH OR WITHOUT SUFFIX '" + fileStr |
| 529 |
|
+ "'"; |
| 530 |
0 |
if (e instanceof FileNotFoundException |
| 531 |
|
|| e instanceof UnknownHostException |
| 532 |
|
|| e instanceof SocketTimeoutException) |
| 533 |
|
{ |
| 534 |
0 |
filenotfound = true; |
| 535 |
|
} |
| 536 |
0 |
throw (e); |
| 537 |
|
} |
| 538 |
|
} |
| 539 |
|
} |
| 540 |
|
} catch (Exception e) |
| 541 |
|
{ |
| 542 |
0 |
errormessage = "CANNOT ACCESS DATA AT URL '" + fileStr + "' (" |
| 543 |
|
+ e.getMessage() + ")"; |
| 544 |
0 |
error = true; |
| 545 |
|
} |
| 546 |
|
} |
| 547 |
0 |
else if (sourceType == DataSourceType.PASTE) |
| 548 |
|
{ |
| 549 |
0 |
errormessage = "PASTE INACCESSIBLE!"; |
| 550 |
0 |
dataIn = new BufferedReader(new StringReader(fileStr)); |
| 551 |
0 |
dataName = "Paste"; |
| 552 |
|
} |
| 553 |
0 |
else if (sourceType == DataSourceType.CLASSLOADER) |
| 554 |
|
{ |
| 555 |
0 |
errormessage = "RESOURCE CANNOT BE LOCATED"; |
| 556 |
0 |
InputStream is = getClass().getResourceAsStream("/" + fileStr); |
| 557 |
0 |
if (is == null) |
| 558 |
|
{ |
| 559 |
0 |
String suffixLess = extractSuffix(fileStr); |
| 560 |
0 |
if (suffixLess != null) |
| 561 |
|
{ |
| 562 |
0 |
is = getClass().getResourceAsStream("/" + suffixLess); |
| 563 |
|
} |
| 564 |
|
} |
| 565 |
0 |
if (is != null) |
| 566 |
|
{ |
| 567 |
0 |
dataIn = new BufferedReader(new InputStreamReader(is)); |
| 568 |
0 |
dataName = fileStr; |
| 569 |
|
} |
| 570 |
|
else |
| 571 |
|
{ |
| 572 |
0 |
error = true; |
| 573 |
|
} |
| 574 |
|
} |
| 575 |
|
else |
| 576 |
|
{ |
| 577 |
0 |
errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" |
| 578 |
0 |
+ (sourceType != null ? sourceType : "null") + "'"; |
| 579 |
0 |
error = true; |
| 580 |
|
} |
| 581 |
0 |
if (dataIn == null || error) |
| 582 |
|
{ |
| 583 |
|
|
| 584 |
0 |
if (filenotfound) |
| 585 |
|
{ |
| 586 |
0 |
throw new FileNotFoundException(MessageManager |
| 587 |
|
.formatMessage("label.url_not_found", new String[] |
| 588 |
|
{ errormessage })); |
| 589 |
|
} |
| 590 |
0 |
throw new IOException(MessageManager.formatMessage( |
| 591 |
|
"exception.failed_to_read_data_from_source", new String[] |
| 592 |
|
{ errormessage })); |
| 593 |
|
} |
| 594 |
0 |
error = false; |
| 595 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
| 596 |
|
} |
| 597 |
|
|
| 598 |
|
|
| 599 |
|
|
| 600 |
|
|
| 601 |
|
|
| 602 |
|
@throws |
| 603 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 604 |
0 |
public void mark() throws IOException... |
| 605 |
|
{ |
| 606 |
0 |
if (dataIn != null) |
| 607 |
|
{ |
| 608 |
0 |
dataIn.mark(READAHEAD_LIMIT); |
| 609 |
|
} |
| 610 |
|
else |
| 611 |
|
{ |
| 612 |
0 |
throw new IOException( |
| 613 |
|
MessageManager.getString("exception.no_init_source_stream")); |
| 614 |
|
} |
| 615 |
|
} |
| 616 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 617 |
0 |
public String nextLine() throws IOException... |
| 618 |
|
{ |
| 619 |
0 |
if (!error) |
| 620 |
|
{ |
| 621 |
0 |
return dataIn.readLine(); |
| 622 |
|
} |
| 623 |
0 |
throw new IOException(MessageManager |
| 624 |
|
.formatMessage("exception.invalid_source_stream", new String[] |
| 625 |
|
{ errormessage })); |
| 626 |
|
} |
| 627 |
|
|
| 628 |
|
|
| 629 |
|
|
| 630 |
|
@return |
| 631 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 632 |
0 |
public boolean isExporting()... |
| 633 |
|
{ |
| 634 |
0 |
return !error && dataIn == null; |
| 635 |
|
} |
| 636 |
|
|
| 637 |
|
|
| 638 |
|
|
| 639 |
|
@return |
| 640 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 641 |
0 |
public boolean isValid()... |
| 642 |
|
{ |
| 643 |
0 |
return !error; |
| 644 |
|
} |
| 645 |
|
|
| 646 |
|
|
| 647 |
|
|
| 648 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 649 |
0 |
public void close() throws IOException... |
| 650 |
|
{ |
| 651 |
0 |
errormessage = "EXCEPTION ON CLOSE"; |
| 652 |
0 |
error = true; |
| 653 |
0 |
dataIn.close(); |
| 654 |
0 |
dataIn = null; |
| 655 |
0 |
errormessage = "SOURCE IS CLOSED"; |
| 656 |
|
} |
| 657 |
|
|
| 658 |
|
|
| 659 |
|
|
| 660 |
|
|
| 661 |
|
@param |
| 662 |
|
|
| 663 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 664 |
0 |
public void reset(int bytesRead) throws IOException... |
| 665 |
|
{ |
| 666 |
0 |
if (bytesRead >= READAHEAD_LIMIT) |
| 667 |
|
{ |
| 668 |
0 |
jalview.bin.Console.errPrintln(String.format( |
| 669 |
|
"File reset error: read %d bytes but reset limit is %d", |
| 670 |
|
bytesRead, READAHEAD_LIMIT)); |
| 671 |
|
} |
| 672 |
0 |
if (dataIn != null && !error) |
| 673 |
|
{ |
| 674 |
0 |
dataIn.reset(); |
| 675 |
|
} |
| 676 |
|
else |
| 677 |
|
{ |
| 678 |
0 |
throw new IOException(MessageManager.getString( |
| 679 |
|
"error.implementation_error_reset_called_for_invalid_source")); |
| 680 |
|
} |
| 681 |
|
} |
| 682 |
|
|
| 683 |
|
|
| 684 |
|
|
| 685 |
|
@return |
| 686 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 687 |
0 |
public boolean hasWarningMessage()... |
| 688 |
|
{ |
| 689 |
0 |
return (warningMessage != null && warningMessage.length() > 0); |
| 690 |
|
} |
| 691 |
|
|
| 692 |
|
|
| 693 |
|
|
| 694 |
|
@return |
| 695 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 696 |
0 |
public String getWarningMessage()... |
| 697 |
|
{ |
| 698 |
0 |
return warningMessage; |
| 699 |
|
} |
| 700 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 701 |
0 |
public String getInFile()... |
| 702 |
|
{ |
| 703 |
0 |
if (inFile != null) |
| 704 |
|
{ |
| 705 |
0 |
return inFile.getAbsolutePath() + " (" + index + ")"; |
| 706 |
|
} |
| 707 |
|
else |
| 708 |
|
{ |
| 709 |
0 |
return "From Paste + (" + index + ")"; |
| 710 |
|
} |
| 711 |
|
} |
| 712 |
|
|
| 713 |
|
|
| 714 |
|
@return |
| 715 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 716 |
0 |
public String getDataName()... |
| 717 |
|
{ |
| 718 |
0 |
return dataName; |
| 719 |
|
} |
| 720 |
|
|
| 721 |
|
|
| 722 |
|
|
| 723 |
|
|
| 724 |
|
@param |
| 725 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 726 |
0 |
protected void setDataName(String dataname)... |
| 727 |
|
{ |
| 728 |
0 |
dataName = dataname; |
| 729 |
|
} |
| 730 |
|
|
| 731 |
|
|
| 732 |
|
|
| 733 |
|
|
| 734 |
|
@return |
| 735 |
|
@throws |
| 736 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 737 |
0 |
public Reader getReader()... |
| 738 |
|
{ |
| 739 |
0 |
if (dataIn != null) |
| 740 |
|
|
| 741 |
|
{ |
| 742 |
0 |
return dataIn; |
| 743 |
|
} |
| 744 |
0 |
return null; |
| 745 |
|
} |
| 746 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 747 |
0 |
public AlignViewportI getViewport()... |
| 748 |
|
{ |
| 749 |
0 |
return viewport; |
| 750 |
|
} |
| 751 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 752 |
0 |
public void setViewport(AlignViewportI viewport)... |
| 753 |
|
{ |
| 754 |
0 |
this.viewport = viewport; |
| 755 |
|
} |
| 756 |
|
|
| 757 |
|
|
| 758 |
|
@return |
| 759 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 760 |
0 |
public AlignExportSettingsI getExportSettings()... |
| 761 |
|
{ |
| 762 |
0 |
return exportSettings; |
| 763 |
|
} |
| 764 |
|
|
| 765 |
|
|
| 766 |
|
|
| 767 |
|
|
| 768 |
|
@param |
| 769 |
|
|
| 770 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 771 |
0 |
public void setExportSettings(AlignExportSettingsI exportSettings)... |
| 772 |
|
{ |
| 773 |
0 |
this.exportSettings = exportSettings; |
| 774 |
|
} |
| 775 |
|
|
| 776 |
|
|
| 777 |
|
|
| 778 |
|
|
| 779 |
|
|
| 780 |
|
@param |
| 781 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 782 |
0 |
public void configureForView(AlignmentViewPanel avpanel)... |
| 783 |
|
{ |
| 784 |
0 |
if (avpanel != null) |
| 785 |
|
{ |
| 786 |
0 |
setViewport(avpanel.getAlignViewport()); |
| 787 |
|
} |
| 788 |
|
|
| 789 |
|
} |
| 790 |
|
|
| 791 |
|
|
| 792 |
|
|
| 793 |
|
|
| 794 |
|
|
| 795 |
|
@return |
| 796 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 797 |
0 |
public FeatureSettingsModelI getFeatureColourScheme()... |
| 798 |
|
{ |
| 799 |
0 |
return null; |
| 800 |
|
} |
| 801 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 802 |
0 |
public DataSourceType getDataSourceType()... |
| 803 |
|
{ |
| 804 |
0 |
return dataSourceType; |
| 805 |
|
} |
| 806 |
|
|
| 807 |
|
|
| 808 |
|
|
| 809 |
|
|
| 810 |
|
|
| 811 |
|
@param |
| 812 |
|
|
| 813 |
|
@param |
| 814 |
|
@return |
| 815 |
|
@throws |
| 816 |
|
|
| |
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 10 |
Complexity Density: 0.36 |
|
| 817 |
0 |
public BufferedReader getBufferedReader(Object file,... |
| 818 |
|
DataSourceType sourceType) throws IOException |
| 819 |
|
{ |
| 820 |
0 |
BufferedReader in = null; |
| 821 |
0 |
byte[] bytes; |
| 822 |
|
|
| 823 |
0 |
switch (sourceType) |
| 824 |
|
{ |
| 825 |
0 |
case FILE: |
| 826 |
0 |
if (file instanceof String) |
| 827 |
|
{ |
| 828 |
0 |
return new BufferedReader(new FileReader((String) file)); |
| 829 |
|
} |
| 830 |
0 |
bytes = Platform.getFileBytes((File) file); |
| 831 |
0 |
if (bytes != null) |
| 832 |
|
{ |
| 833 |
0 |
return new BufferedReader( |
| 834 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
| 835 |
|
} |
| 836 |
0 |
return new BufferedReader(new FileReader((File) file)); |
| 837 |
0 |
case URL: |
| 838 |
0 |
URL url = new URL(file.toString()); |
| 839 |
0 |
in = new BufferedReader( |
| 840 |
|
new InputStreamReader(HttpUtils.openStream(url))); |
| 841 |
0 |
break; |
| 842 |
0 |
case RELATIVE_URL: |
| 843 |
0 |
bytes = Platform.getFileAsBytes(file.toString()); |
| 844 |
0 |
if (bytes != null) |
| 845 |
|
{ |
| 846 |
0 |
in = new BufferedReader( |
| 847 |
|
new InputStreamReader(new ByteArrayInputStream(bytes))); |
| 848 |
|
} |
| 849 |
0 |
break; |
| 850 |
0 |
case PASTE: |
| 851 |
0 |
in = new BufferedReader(new StringReader(file.toString())); |
| 852 |
0 |
break; |
| 853 |
0 |
case CLASSLOADER: |
| 854 |
0 |
InputStream is = getClass().getResourceAsStream("/" + file); |
| 855 |
0 |
if (is != null) |
| 856 |
|
{ |
| 857 |
0 |
in = new BufferedReader(new InputStreamReader(is)); |
| 858 |
|
} |
| 859 |
0 |
break; |
| 860 |
|
} |
| 861 |
|
|
| 862 |
0 |
return in; |
| 863 |
|
} |
| 864 |
|
} |