| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.util; |
| 22 |
|
|
| 23 |
|
import java.awt.Component; |
| 24 |
|
import java.awt.Dimension; |
| 25 |
|
import java.awt.GraphicsEnvironment; |
| 26 |
|
import java.awt.Toolkit; |
| 27 |
|
import java.awt.event.KeyEvent; |
| 28 |
|
import java.awt.event.MouseEvent; |
| 29 |
|
import java.io.BufferedReader; |
| 30 |
|
import java.io.File; |
| 31 |
|
import java.io.FileOutputStream; |
| 32 |
|
import java.io.FileReader; |
| 33 |
|
import java.io.IOException; |
| 34 |
|
import java.io.InputStream; |
| 35 |
|
import java.io.InputStreamReader; |
| 36 |
|
import java.io.Reader; |
| 37 |
|
import java.lang.reflect.Method; |
| 38 |
|
import java.net.URL; |
| 39 |
|
import java.nio.channels.Channels; |
| 40 |
|
import java.nio.channels.ReadableByteChannel; |
| 41 |
|
import java.nio.file.Files; |
| 42 |
|
import java.nio.file.Path; |
| 43 |
|
import java.nio.file.Paths; |
| 44 |
|
import java.nio.file.StandardCopyOption; |
| 45 |
|
import java.nio.file.attribute.BasicFileAttributes; |
| 46 |
|
import java.util.Date; |
| 47 |
|
import java.util.Locale; |
| 48 |
|
import java.util.Map; |
| 49 |
|
import java.util.Objects; |
| 50 |
|
import java.util.Properties; |
| 51 |
|
import java.util.logging.ConsoleHandler; |
| 52 |
|
import java.util.logging.Level; |
| 53 |
|
import java.util.logging.Logger; |
| 54 |
|
|
| 55 |
|
import javax.swing.SwingUtilities; |
| 56 |
|
|
| 57 |
|
import org.json.simple.parser.JSONParser; |
| 58 |
|
import org.json.simple.parser.ParseException; |
| 59 |
|
|
| 60 |
|
import com.stevesoft.pat.Regex; |
| 61 |
|
|
| 62 |
|
import jalview.bin.Jalview; |
| 63 |
|
import jalview.javascript.json.JSON; |
| 64 |
|
import swingjs.api.JSUtilI; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@author |
| 70 |
|
|
| |
|
| 0% |
Uncovered Elements: 404 (404) |
Complexity: 153 |
Complexity Density: 0.7 |
|
| 71 |
|
public class Platform |
| 72 |
|
{ |
| 73 |
|
|
| 74 |
|
private static boolean isJS = |
| 75 |
|
false; |
| 76 |
|
|
| 77 |
|
private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null, |
| 78 |
|
isWin = null, isLinux = null; |
| 79 |
|
|
| 80 |
|
private static Boolean isHeadless = null; |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
private static final int CONSOLEWIDTH; |
| 84 |
|
|
| 85 |
|
private static final String CONSOLEWIDTHPROPERTY = "CONSOLEWIDTH"; |
| 86 |
|
|
| 87 |
|
private static swingjs.api.JSUtilI jsutil; |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
@return |
| 93 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 94 |
0 |
public static boolean isMac()... |
| 95 |
|
{ |
| 96 |
0 |
return (isMac == null |
| 97 |
|
? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) |
| 98 |
|
: isMac); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public static int SHORTCUT_KEY_MASK = (Platform.isMac() |
| 102 |
|
? KeyEvent.META_DOWN_MASK |
| 103 |
|
: KeyEvent.CTRL_DOWN_MASK); |
| 104 |
|
|
| |
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 13 |
Complexity Density: 0.48 |
|
| 105 |
0 |
static... |
| 106 |
|
{ |
| 107 |
0 |
int cw = 80; |
| 108 |
0 |
if (System.getProperty(CONSOLEWIDTHPROPERTY) != null |
| 109 |
|
&& System.getProperty(CONSOLEWIDTHPROPERTY).length() > 0) |
| 110 |
|
{ |
| 111 |
0 |
try |
| 112 |
|
{ |
| 113 |
0 |
cw = Integer.parseInt(System.getProperty(CONSOLEWIDTHPROPERTY)); |
| 114 |
|
} catch (NumberFormatException e) |
| 115 |
|
{ |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
0 |
CONSOLEWIDTH = cw; |
| 119 |
0 |
if (isJS) |
| 120 |
|
{ |
| 121 |
0 |
try |
| 122 |
|
{ |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
0 |
jsutil = ((JSUtilI) Class.forName("swingjs.JSUtil").newInstance()); |
| 127 |
|
} catch (InstantiationException | IllegalAccessException |
| 128 |
|
| ClassNotFoundException e) |
| 129 |
|
{ |
| 130 |
0 |
e.printStackTrace(); |
| 131 |
|
} |
| 132 |
|
} |
| 133 |
0 |
if (!GraphicsEnvironment.isHeadless()) |
| 134 |
|
{ |
| 135 |
|
|
| 136 |
|
|
| 137 |
0 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
| 138 |
0 |
Method method = null; |
| 139 |
0 |
try |
| 140 |
|
{ |
| 141 |
0 |
method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx"); |
| 142 |
|
} catch (Exception e) |
| 143 |
|
{ |
| 144 |
0 |
System.err.println( |
| 145 |
|
"Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask."); |
| 146 |
|
} |
| 147 |
0 |
if (method == null) |
| 148 |
|
{ |
| 149 |
0 |
try |
| 150 |
|
{ |
| 151 |
0 |
method = tk.getClass().getMethod("getMenuShortcutKeyMask"); |
| 152 |
|
} catch (Exception e) |
| 153 |
|
{ |
| 154 |
0 |
System.err.println( |
| 155 |
|
"Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask."); |
| 156 |
0 |
e.printStackTrace(); |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
0 |
if (method != null) |
| 160 |
|
{ |
| 161 |
0 |
try |
| 162 |
|
{ |
| 163 |
0 |
method.setAccessible(true); |
| 164 |
0 |
SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0])); |
| 165 |
|
} catch (Exception e) |
| 166 |
|
{ |
| 167 |
0 |
e.printStackTrace(); |
| 168 |
|
} |
| 169 |
|
} |
| 170 |
0 |
if (SHORTCUT_KEY_MASK <= 0xF) |
| 171 |
|
{ |
| 172 |
|
|
| 173 |
0 |
SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6; |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
@return |
| 182 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 183 |
0 |
public static boolean isWin()... |
| 184 |
|
{ |
| 185 |
0 |
return (isWin == null |
| 186 |
|
? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) |
| 187 |
|
: isWin); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
@return |
| 194 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 195 |
0 |
public static boolean isLinux()... |
| 196 |
|
{ |
| 197 |
0 |
return (isLinux == null |
| 198 |
|
? (isLinux = (System.getProperty("os.name") |
| 199 |
|
.indexOf("Linux") >= 0)) |
| 200 |
|
: isLinux); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
@return |
| 206 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 207 |
0 |
public static boolean isJS()... |
| 208 |
|
{ |
| 209 |
0 |
return isJS; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
@return |
| 218 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 219 |
0 |
public static boolean isAMacAndNotJS()... |
| 220 |
|
{ |
| 221 |
0 |
return (isNoJSMac == null ? (isNoJSMac = !isJS && isMac()) : isNoJSMac); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
@return |
| 228 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 229 |
0 |
public static boolean isWindowsAndNotJS()... |
| 230 |
|
{ |
| 231 |
0 |
return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
@return |
| 237 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 238 |
0 |
public static boolean isHeadless()... |
| 239 |
|
{ |
| 240 |
0 |
if (isHeadless == null) |
| 241 |
|
{ |
| 242 |
0 |
isHeadless = "true".equals(System.getProperty("java.awt.headless")); |
| 243 |
|
} |
| 244 |
0 |
return isHeadless; |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
@link |
| 251 |
|
|
| 252 |
|
|
| 253 |
|
|
| 254 |
|
|
| 255 |
|
|
| 256 |
|
@param |
| 257 |
|
|
| 258 |
|
@param |
| 259 |
|
|
| 260 |
|
@return |
| 261 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 262 |
0 |
public static <T> PlatformDependentValue<T> forArch(T defaultValue)... |
| 263 |
|
{ |
| 264 |
0 |
return new PlatformDependentValue<T>(defaultValue); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
@author |
| 270 |
|
|
| 271 |
|
@param |
| 272 |
|
|
| 273 |
|
|
| |
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 17 |
Complexity Density: 0.61 |
|
| 274 |
|
public static class PlatformDependentValue<T> |
| 275 |
|
{ |
| 276 |
|
private T defaultValue = null; |
| 277 |
|
|
| 278 |
|
private T macValue = null; |
| 279 |
|
|
| 280 |
|
private T winValue = null; |
| 281 |
|
|
| 282 |
|
private T linuxValue = null; |
| 283 |
|
|
| 284 |
|
private T jsValue = null; |
| 285 |
|
|
| 286 |
|
private T headlessValue = null; |
| 287 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 288 |
0 |
private PlatformDependentValue(T value)... |
| 289 |
|
{ |
| 290 |
0 |
Objects.requireNonNull(value); |
| 291 |
0 |
defaultValue = value; |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
@param |
| 298 |
|
|
| 299 |
|
@return |
| 300 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 301 |
0 |
public PlatformDependentValue<T> forMac(T value)... |
| 302 |
|
{ |
| 303 |
0 |
Objects.requireNonNull(value); |
| 304 |
0 |
macValue = value; |
| 305 |
0 |
return this; |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
|
@param |
| 312 |
|
|
| 313 |
|
@return |
| 314 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 315 |
0 |
public PlatformDependentValue<T> forWin(T value)... |
| 316 |
|
{ |
| 317 |
0 |
Objects.requireNonNull(value); |
| 318 |
0 |
winValue = value; |
| 319 |
0 |
return this; |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
|
| 323 |
|
|
| 324 |
|
|
| 325 |
|
@param |
| 326 |
|
|
| 327 |
|
@return |
| 328 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 329 |
0 |
public PlatformDependentValue<T> forLinux(T value)... |
| 330 |
|
{ |
| 331 |
0 |
Objects.requireNonNull(value); |
| 332 |
0 |
linuxValue = value; |
| 333 |
0 |
return this; |
| 334 |
|
} |
| 335 |
|
|
| 336 |
|
|
| 337 |
|
|
| 338 |
|
|
| 339 |
|
@param |
| 340 |
|
|
| 341 |
|
@return |
| 342 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 343 |
0 |
public PlatformDependentValue<T> forJS(T value)... |
| 344 |
|
{ |
| 345 |
0 |
Objects.requireNonNull(value); |
| 346 |
0 |
jsValue = value; |
| 347 |
0 |
return this; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
| 353 |
|
|
| 354 |
|
@param |
| 355 |
|
|
| 356 |
|
@return |
| 357 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 358 |
0 |
public PlatformDependentValue<T> forHeadless(T value)... |
| 359 |
|
{ |
| 360 |
0 |
Objects.requireNonNull(value); |
| 361 |
0 |
headlessValue = value; |
| 362 |
0 |
return this; |
| 363 |
|
} |
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
|
|
| 368 |
|
|
| 369 |
|
|
| 370 |
|
@return |
| 371 |
|
|
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 11 |
Complexity Density: 1 |
|
| 372 |
0 |
public T value()... |
| 373 |
|
{ |
| 374 |
0 |
if (headlessValue != null && isHeadless()) |
| 375 |
0 |
return headlessValue; |
| 376 |
0 |
if (macValue != null && isMac()) |
| 377 |
0 |
return macValue; |
| 378 |
0 |
if (winValue != null && isWin()) |
| 379 |
0 |
return winValue; |
| 380 |
0 |
if (linuxValue != null && isLinux()) |
| 381 |
0 |
return linuxValue; |
| 382 |
0 |
if (jsValue != null && isJS) |
| 383 |
0 |
return jsValue; |
| 384 |
0 |
return defaultValue; |
| 385 |
|
} |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
|
| 390 |
|
@return |
| 391 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 392 |
0 |
public static int getMaxCommandLineLength()... |
| 393 |
|
{ |
| 394 |
|
|
| 395 |
0 |
return 2046; |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
|
| 399 |
|
|
| 400 |
|
|
| 401 |
|
|
| 402 |
|
@param |
| 403 |
|
@return |
| 404 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 405 |
0 |
public static String escapeBackslashes(String s)... |
| 406 |
|
{ |
| 407 |
0 |
return s == null ? null : s.replace("\\", "\\\\"); |
| 408 |
|
} |
| 409 |
|
|
| 410 |
|
|
| 411 |
|
|
| 412 |
|
|
| 413 |
|
|
| 414 |
|
|
| 415 |
|
|
| 416 |
|
@param |
| 417 |
|
@return |
| 418 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 419 |
0 |
public static boolean isControlDown(MouseEvent e)... |
| 420 |
|
{ |
| 421 |
0 |
return isControlDown(e, isMac()); |
| 422 |
|
} |
| 423 |
|
|
| 424 |
|
|
| 425 |
|
|
| 426 |
|
|
| 427 |
|
@param |
| 428 |
|
@param |
| 429 |
|
@return |
| 430 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 431 |
0 |
protected static boolean isControlDown(MouseEvent e, boolean aMac)... |
| 432 |
|
{ |
| 433 |
|
|
| 434 |
|
|
| 435 |
|
|
| 436 |
|
|
| 437 |
0 |
return (aMac |
| 438 |
|
? !e.isPopupTrigger() |
| 439 |
|
&& (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0 |
| 440 |
|
: e.isControlDown()); |
| 441 |
|
} |
| 442 |
|
|
| 443 |
|
|
| 444 |
|
|
| 445 |
|
|
| 446 |
|
|
| 447 |
|
|
| 448 |
|
|
| 449 |
|
|
| 450 |
|
|
| 451 |
|
|
| 452 |
|
|
| 453 |
|
|
| 454 |
|
|
| 455 |
|
|
| 456 |
|
|
| 457 |
|
|
| 458 |
|
|
| 459 |
|
|
| 460 |
|
|
| 461 |
|
|
| 462 |
|
|
| 463 |
|
|
| 464 |
|
|
| 465 |
|
|
| 466 |
|
|
| 467 |
|
|
| 468 |
|
|
| 469 |
|
|
| 470 |
|
|
| 471 |
|
|
| 472 |
|
|
| 473 |
|
|
| 474 |
|
|
| 475 |
|
|
| 476 |
|
@param |
| 477 |
|
@return |
| 478 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 479 |
0 |
public static boolean isWinRightButton(MouseEvent e)... |
| 480 |
|
{ |
| 481 |
|
|
| 482 |
|
|
| 483 |
0 |
return isWin() && SwingUtilities.isRightMouseButton(e); |
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
|
| 487 |
|
|
| 488 |
|
|
| 489 |
|
|
| 490 |
|
@param |
| 491 |
|
@return |
| 492 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 493 |
0 |
public static boolean isWinMiddleButton(MouseEvent e)... |
| 494 |
|
{ |
| 495 |
|
|
| 496 |
0 |
return isWin() && SwingUtilities.isMiddleMouseButton(e); |
| 497 |
|
} |
| 498 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 499 |
0 |
public static boolean allowMnemonics()... |
| 500 |
|
{ |
| 501 |
0 |
return !isMac(); |
| 502 |
|
} |
| 503 |
|
|
| 504 |
|
public final static int TIME_RESET = 0; |
| 505 |
|
|
| 506 |
|
public final static int TIME_MARK = 1; |
| 507 |
|
|
| 508 |
|
public static final int TIME_SET = 2; |
| 509 |
|
|
| 510 |
|
public static final int TIME_GET = 3; |
| 511 |
|
|
| 512 |
|
public static long time, mark, set, duration; |
| 513 |
|
|
| 514 |
|
|
| 515 |
|
|
| 516 |
|
|
| 517 |
|
|
| 518 |
|
|
| 519 |
|
|
| 520 |
|
|
| 521 |
|
|
| 522 |
|
|
| 523 |
|
|
| 524 |
|
|
| 525 |
|
@param |
| 526 |
|
@param |
| 527 |
|
|
| |
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 10 |
Complexity Density: 0.4 |
|
| 528 |
0 |
public static void timeCheck(String msg, int mode)... |
| 529 |
|
{ |
| 530 |
0 |
long t = System.currentTimeMillis(); |
| 531 |
0 |
switch (mode) |
| 532 |
|
{ |
| 533 |
0 |
case TIME_RESET: |
| 534 |
0 |
time = mark = t; |
| 535 |
0 |
duration = 0; |
| 536 |
0 |
if (msg != null) |
| 537 |
|
{ |
| 538 |
0 |
jalview.bin.Console.errPrintln("Platform: timer reset\t\t\t" + msg); |
| 539 |
|
} |
| 540 |
0 |
break; |
| 541 |
0 |
case TIME_MARK: |
| 542 |
0 |
if (set > 0) |
| 543 |
|
{ |
| 544 |
|
|
| 545 |
0 |
duration += (t - set); |
| 546 |
|
} |
| 547 |
|
else |
| 548 |
|
{ |
| 549 |
0 |
if (time == 0) |
| 550 |
|
{ |
| 551 |
0 |
time = mark = t; |
| 552 |
|
} |
| 553 |
0 |
if (msg != null) |
| 554 |
|
{ |
| 555 |
0 |
jalview.bin.Console.errPrintln( |
| 556 |
|
"Platform: timer mark\t" + ((t - time) / 1000f) + "\t" |
| 557 |
|
+ ((t - mark) / 1000f) + "\t" + msg); |
| 558 |
|
} |
| 559 |
0 |
mark = t; |
| 560 |
|
} |
| 561 |
0 |
break; |
| 562 |
0 |
case TIME_SET: |
| 563 |
0 |
set = t; |
| 564 |
0 |
break; |
| 565 |
0 |
case TIME_GET: |
| 566 |
0 |
if (msg != null) |
| 567 |
|
{ |
| 568 |
0 |
jalview.bin.Console |
| 569 |
|
.errPrintln("Platform: timer dur\t" + ((t - time) / 1000f) |
| 570 |
|
+ "\t" + ((duration) / 1000f) + "\t" + msg); |
| 571 |
|
} |
| 572 |
0 |
set = 0; |
| 573 |
0 |
break; |
| 574 |
|
} |
| 575 |
|
} |
| 576 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
| 577 |
0 |
public static void cacheFileData(String path, Object data)... |
| 578 |
|
{ |
| 579 |
0 |
if (isJS && data != null) |
| 580 |
|
{ |
| 581 |
0 |
jsutil.cachePathData(path, data); |
| 582 |
|
} |
| 583 |
|
} |
| 584 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 585 |
0 |
public static void cacheFileData(File file)... |
| 586 |
|
{ |
| 587 |
0 |
if (isJS) |
| 588 |
|
{ |
| 589 |
0 |
byte[] data = Platform.getFileBytes(file); |
| 590 |
|
{ |
| 591 |
0 |
if (data != null) |
| 592 |
|
{ |
| 593 |
0 |
cacheFileData(file.toString(), data); |
| 594 |
|
} |
| 595 |
|
} |
| 596 |
|
} |
| 597 |
|
} |
| 598 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
| 599 |
0 |
public static byte[] getFileBytes(File f)... |
| 600 |
|
{ |
| 601 |
0 |
return (isJS && f != null ? jsutil.getBytes(f) : null); |
| 602 |
|
} |
| 603 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 604 |
0 |
public static byte[] getFileAsBytes(String fileStr)... |
| 605 |
|
{ |
| 606 |
0 |
if (isJS && fileStr != null) |
| 607 |
|
{ |
| 608 |
0 |
byte[] bytes = (byte[]) jsutil.getFile(fileStr, false); |
| 609 |
0 |
cacheFileData(fileStr, bytes); |
| 610 |
0 |
return bytes; |
| 611 |
|
} |
| 612 |
0 |
return null; |
| 613 |
|
} |
| 614 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 615 |
0 |
public static String getFileAsString(String url)... |
| 616 |
|
{ |
| 617 |
0 |
if (isJS && url != null) |
| 618 |
|
{ |
| 619 |
0 |
String ret = (String) jsutil.getFile(url, true); |
| 620 |
0 |
cacheFileData(url, ret); |
| 621 |
0 |
return ret; |
| 622 |
|
} |
| 623 |
0 |
return null; |
| 624 |
|
} |
| 625 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 626 |
0 |
public static boolean setFileBytes(File f, String urlstring)... |
| 627 |
|
{ |
| 628 |
0 |
if (isJS && f != null && urlstring != null) |
| 629 |
|
{ |
| 630 |
0 |
@SuppressWarnings("unused") |
| 631 |
|
byte[] bytes = getFileAsBytes(urlstring); |
| 632 |
0 |
jsutil.setFileBytes(f, bytes); |
| 633 |
0 |
return true; |
| 634 |
|
} |
| 635 |
0 |
return false; |
| 636 |
|
} |
| 637 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 638 |
0 |
public static void addJ2SBinaryType(String ext)... |
| 639 |
|
{ |
| 640 |
0 |
if (isJS) |
| 641 |
|
{ |
| 642 |
0 |
jsutil.addBinaryFileType(ext); |
| 643 |
|
} |
| 644 |
|
} |
| 645 |
|
|
| 646 |
|
|
| 647 |
|
|
| 648 |
|
|
| 649 |
|
@param |
| 650 |
|
@return |
| 651 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 652 |
0 |
public static String encodeURI(String value)... |
| 653 |
|
{ |
| 654 |
|
|
| 655 |
|
|
| 656 |
|
|
| 657 |
0 |
return value; |
| 658 |
|
} |
| 659 |
|
|
| 660 |
|
|
| 661 |
|
|
| 662 |
|
|
| 663 |
|
@param |
| 664 |
|
@return |
| 665 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 666 |
0 |
public static boolean openURL(String url) throws IOException... |
| 667 |
|
{ |
| 668 |
0 |
if (!isJS) |
| 669 |
|
{ |
| 670 |
0 |
return false; |
| 671 |
|
} |
| 672 |
|
|
| 673 |
|
|
| 674 |
|
|
| 675 |
|
|
| 676 |
|
|
| 677 |
|
|
| 678 |
0 |
return true; |
| 679 |
|
} |
| 680 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 681 |
0 |
public static String getUniqueAppletID()... |
| 682 |
|
{ |
| 683 |
0 |
return (isJS ? (String) jsutil.getAppletAttribute("_uniqueId") : null); |
| 684 |
|
|
| 685 |
|
} |
| 686 |
|
|
| 687 |
|
|
| 688 |
|
|
| 689 |
|
|
| 690 |
|
@param |
| 691 |
|
|
| 692 |
|
@param |
| 693 |
|
@return |
| 694 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 695 |
0 |
public static void readInfoProperties(String prefix, Properties p)... |
| 696 |
|
{ |
| 697 |
0 |
if (!isJS) |
| 698 |
|
{ |
| 699 |
0 |
return; |
| 700 |
|
} |
| 701 |
0 |
String id = getUniqueAppletID(); |
| 702 |
0 |
String key = "", value = ""; |
| 703 |
|
|
| 704 |
|
|
| 705 |
|
|
| 706 |
|
|
| 707 |
|
|
| 708 |
|
|
| 709 |
0 |
jalview.bin.Console.outPrintln( |
| 710 |
|
"Platform id=" + id + " reading Info." + key + " = " + value); |
| 711 |
0 |
p.put(id + "_" + key, value); |
| 712 |
|
|
| 713 |
|
|
| 714 |
|
|
| 715 |
|
|
| 716 |
|
|
| 717 |
|
|
| 718 |
|
} |
| 719 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 720 |
0 |
public static void setAjaxJSON(URL url)... |
| 721 |
|
{ |
| 722 |
0 |
if (isJS) |
| 723 |
|
{ |
| 724 |
0 |
JSON.setAjax(url); |
| 725 |
|
} |
| 726 |
|
} |
| 727 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 728 |
0 |
public static Object parseJSON(InputStream response)... |
| 729 |
|
throws IOException, ParseException |
| 730 |
|
{ |
| 731 |
0 |
if (isJS) |
| 732 |
|
{ |
| 733 |
0 |
return JSON.parse(response); |
| 734 |
|
} |
| 735 |
|
|
| 736 |
0 |
BufferedReader br = null; |
| 737 |
0 |
try |
| 738 |
|
{ |
| 739 |
0 |
br = new BufferedReader(new InputStreamReader(response, "UTF-8")); |
| 740 |
0 |
return new JSONParser().parse(br); |
| 741 |
|
} finally |
| 742 |
|
{ |
| 743 |
0 |
if (br != null) |
| 744 |
|
{ |
| 745 |
0 |
try |
| 746 |
|
{ |
| 747 |
0 |
br.close(); |
| 748 |
|
} catch (IOException e) |
| 749 |
|
{ |
| 750 |
|
|
| 751 |
|
} |
| 752 |
|
} |
| 753 |
|
} |
| 754 |
|
} |
| 755 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 756 |
0 |
public static Object parseJSON(String json) throws ParseException... |
| 757 |
|
{ |
| 758 |
0 |
return (isJS ? JSON.parse(json) : new JSONParser().parse(json)); |
| 759 |
|
} |
| 760 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 761 |
0 |
public static Object parseJSON(Reader r)... |
| 762 |
|
throws IOException, ParseException |
| 763 |
|
{ |
| 764 |
0 |
if (r == null) |
| 765 |
|
{ |
| 766 |
0 |
return null; |
| 767 |
|
} |
| 768 |
|
|
| 769 |
0 |
if (!isJS) |
| 770 |
|
{ |
| 771 |
0 |
return new JSONParser().parse(r); |
| 772 |
|
} |
| 773 |
|
|
| 774 |
|
|
| 775 |
0 |
if (r instanceof FileReader) |
| 776 |
|
{ |
| 777 |
0 |
throw new IOException( |
| 778 |
|
"StringJS does not support FileReader parsing for JSON -- but it could..."); |
| 779 |
|
} |
| 780 |
0 |
return JSON.parse(r); |
| 781 |
|
|
| 782 |
|
} |
| 783 |
|
|
| 784 |
|
|
| 785 |
|
|
| 786 |
|
|
| 787 |
|
@param |
| 788 |
|
@param |
| 789 |
|
@throws |
| 790 |
|
|
| 791 |
|
|
| 792 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 793 |
0 |
public static void streamToFile(InputStream is, File outFile)... |
| 794 |
|
throws IOException |
| 795 |
|
{ |
| 796 |
0 |
if (isJS) |
| 797 |
|
{ |
| 798 |
0 |
jsutil.setFileBytes(outFile, is); |
| 799 |
0 |
return; |
| 800 |
|
} |
| 801 |
0 |
FileOutputStream fio = new FileOutputStream(outFile); |
| 802 |
0 |
try |
| 803 |
|
{ |
| 804 |
0 |
byte[] bb = new byte[32 * 1024]; |
| 805 |
0 |
int l; |
| 806 |
0 |
while ((l = is.read(bb)) > 0) |
| 807 |
|
{ |
| 808 |
0 |
fio.write(bb, 0, l); |
| 809 |
|
} |
| 810 |
|
} finally |
| 811 |
|
{ |
| 812 |
0 |
fio.close(); |
| 813 |
|
} |
| 814 |
|
} |
| 815 |
|
|
| 816 |
|
|
| 817 |
|
|
| 818 |
|
|
| 819 |
|
|
| 820 |
|
|
| 821 |
|
@param |
| 822 |
|
|
| 823 |
|
|
| 824 |
|
@author |
| 825 |
|
|
| 826 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 827 |
0 |
public static void addJ2SDirectDatabaseCall(String domain)... |
| 828 |
|
{ |
| 829 |
|
|
| 830 |
0 |
if (isJS) |
| 831 |
|
{ |
| 832 |
0 |
jsutil.addDirectDatabaseCall(domain); |
| 833 |
0 |
jalview.bin.Console.outPrintln( |
| 834 |
|
"Platform adding known access-control-allow-origin * for domain " |
| 835 |
|
+ domain); |
| 836 |
|
|
| 837 |
|
|
| 838 |
|
|
| 839 |
|
|
| 840 |
|
|
| 841 |
|
} |
| 842 |
|
|
| 843 |
|
} |
| 844 |
|
|
| 845 |
|
|
| 846 |
|
|
| 847 |
|
|
| 848 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 2 |
Complexity Density: 2 |
|
| 849 |
0 |
public static void getURLCommandArguments()... |
| 850 |
|
{ |
| 851 |
0 |
try |
| 852 |
|
{ |
| 853 |
|
|
| 854 |
|
|
| 855 |
|
|
| 856 |
|
|
| 857 |
|
|
| 858 |
|
|
| 859 |
|
|
| 860 |
|
|
| 861 |
|
|
| 862 |
|
|
| 863 |
|
|
| 864 |
|
|
| 865 |
|
|
| 866 |
|
|
| 867 |
|
|
| 868 |
|
|
| 869 |
|
} catch (Throwable t) |
| 870 |
|
{ |
| 871 |
|
} |
| 872 |
|
} |
| 873 |
|
|
| 874 |
|
|
| 875 |
|
|
| 876 |
|
|
| 877 |
|
|
| 878 |
|
@param |
| 879 |
|
@param |
| 880 |
|
@return |
| 881 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 882 |
0 |
public static boolean pathEquals(String path1, String path2)... |
| 883 |
|
{ |
| 884 |
0 |
if (path1 == null) |
| 885 |
|
{ |
| 886 |
0 |
return path2 == null; |
| 887 |
|
} |
| 888 |
0 |
if (path2 == null) |
| 889 |
|
{ |
| 890 |
0 |
return false; |
| 891 |
|
} |
| 892 |
0 |
String p1 = path1.replace('\\', '/'); |
| 893 |
0 |
String p2 = path2.replace('\\', '/'); |
| 894 |
0 |
return p1.equals(p2); |
| 895 |
|
} |
| 896 |
|
|
| 897 |
|
|
| 898 |
|
|
| 899 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 900 |
0 |
public static int consoleWidth()... |
| 901 |
|
{ |
| 902 |
0 |
return CONSOLEWIDTH; |
| 903 |
|
} |
| 904 |
|
|
| 905 |
|
|
| 906 |
|
|
| 907 |
|
|
| 908 |
|
|
| 909 |
|
|
| 910 |
|
@param |
| 911 |
|
|
| 912 |
|
@param |
| 913 |
|
|
| 914 |
|
@param |
| 915 |
|
@return |
| 916 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
| 917 |
0 |
public static Dimension getDimIfEmbedded(Component frame,... |
| 918 |
|
int defaultWidth, int defaultHeight) |
| 919 |
|
{ |
| 920 |
0 |
Dimension d = null; |
| 921 |
0 |
if (isJS) |
| 922 |
|
{ |
| 923 |
0 |
d = (Dimension) getEmbeddedAttribute(frame, "dim"); |
| 924 |
|
} |
| 925 |
0 |
return (d == null && defaultWidth >= 0 |
| 926 |
|
? new Dimension(defaultWidth, defaultHeight) |
| 927 |
|
: d); |
| 928 |
|
|
| 929 |
|
} |
| 930 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 931 |
0 |
public static Regex newRegex(String regex)... |
| 932 |
|
{ |
| 933 |
0 |
return newRegex(regex, null); |
| 934 |
|
} |
| 935 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 936 |
0 |
public static Regex newRegex(String searchString, String replaceString)... |
| 937 |
|
{ |
| 938 |
0 |
ensureRegex(); |
| 939 |
0 |
return (replaceString == null ? new Regex(searchString) |
| 940 |
|
: new Regex(searchString, replaceString)); |
| 941 |
|
} |
| 942 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 943 |
0 |
public static Regex newRegexPerl(String code)... |
| 944 |
|
{ |
| 945 |
0 |
ensureRegex(); |
| 946 |
0 |
return Regex.perlCode(code); |
| 947 |
|
} |
| 948 |
|
|
| 949 |
|
|
| 950 |
|
|
| 951 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 952 |
0 |
public static void startJavaLogging()... |
| 953 |
|
{ |
| 954 |
|
|
| 955 |
|
|
| 956 |
|
|
| 957 |
|
{ |
| 958 |
0 |
logClass("java.awt.EventDispatchThread", "java.awt.EventQueue", |
| 959 |
|
"java.awt.Component", "java.awt.focus.Component", |
| 960 |
|
"java.awt.event.Component", |
| 961 |
|
"java.awt.focus.DefaultKeyboardFocusManager"); |
| 962 |
|
} |
| 963 |
|
} |
| 964 |
|
|
| 965 |
|
|
| 966 |
|
|
| 967 |
|
|
| 968 |
|
|
| 969 |
|
@param |
| 970 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 971 |
0 |
public static void logClass(String... classNames)... |
| 972 |
|
{ |
| 973 |
|
|
| 974 |
|
|
| 975 |
|
|
| 976 |
|
|
| 977 |
|
|
| 978 |
|
{ |
| 979 |
0 |
Logger rootLogger = Logger.getLogger(""); |
| 980 |
0 |
rootLogger.setLevel(Level.ALL); |
| 981 |
0 |
ConsoleHandler consoleHandler = new ConsoleHandler(); |
| 982 |
0 |
consoleHandler.setLevel(Level.ALL); |
| 983 |
0 |
for (int i = classNames.length; --i >= 0;) |
| 984 |
|
{ |
| 985 |
0 |
Logger logger = Logger.getLogger(classNames[i]); |
| 986 |
0 |
logger.setLevel(Level.ALL); |
| 987 |
0 |
logger.addHandler(consoleHandler); |
| 988 |
|
} |
| 989 |
|
} |
| 990 |
|
} |
| 991 |
|
|
| 992 |
|
|
| 993 |
|
|
| 994 |
|
|
| 995 |
|
|
| 996 |
|
|
| 997 |
|
|
| 998 |
|
@param |
| 999 |
|
@param |
| 1000 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 1001 |
0 |
public static void loadStaticResource(String resourcePath,... |
| 1002 |
|
String className) |
| 1003 |
|
{ |
| 1004 |
0 |
if (isJS) |
| 1005 |
|
{ |
| 1006 |
0 |
jsutil.loadResourceIfClassUnknown(resourcePath, className); |
| 1007 |
|
} |
| 1008 |
|
} |
| 1009 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 1010 |
0 |
public static void ensureRegex()... |
| 1011 |
|
{ |
| 1012 |
0 |
if (isJS) |
| 1013 |
|
{ |
| 1014 |
0 |
loadStaticResource("core/core_stevesoft.z.js", |
| 1015 |
|
"com.stevesoft.pat.Regex"); |
| 1016 |
|
} |
| 1017 |
|
} |
| 1018 |
|
|
| 1019 |
|
|
| 1020 |
|
|
| 1021 |
|
|
| 1022 |
|
|
| 1023 |
|
|
| 1024 |
|
|
| 1025 |
|
@param |
| 1026 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 1027 |
0 |
public static void setAppClass(Object j)... |
| 1028 |
|
{ |
| 1029 |
0 |
if (isJS) |
| 1030 |
|
{ |
| 1031 |
0 |
jsutil.setAppClass(j); |
| 1032 |
|
} |
| 1033 |
|
} |
| 1034 |
|
|
| 1035 |
|
|
| 1036 |
|
|
| 1037 |
|
|
| 1038 |
|
|
| 1039 |
|
@param |
| 1040 |
|
|
| 1041 |
|
@param |
| 1042 |
|
|
| 1043 |
|
@return |
| 1044 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 1045 |
0 |
public static Object getEmbeddedAttribute(Component frame, String type)... |
| 1046 |
|
{ |
| 1047 |
0 |
return (isJS ? jsutil.getEmbeddedAttribute(frame, type) : null); |
| 1048 |
|
} |
| 1049 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 1050 |
0 |
public static void stackTrace()... |
| 1051 |
|
{ |
| 1052 |
0 |
try |
| 1053 |
|
{ |
| 1054 |
0 |
throw new NullPointerException(); |
| 1055 |
|
} catch (Exception e) |
| 1056 |
|
{ |
| 1057 |
0 |
e.printStackTrace(); |
| 1058 |
|
} |
| 1059 |
|
|
| 1060 |
|
} |
| 1061 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 1062 |
0 |
public static URL getDocumentBase()... |
| 1063 |
|
{ |
| 1064 |
0 |
return (isJS ? jsutil.getDocumentBase() : null); |
| 1065 |
|
} |
| 1066 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 1067 |
0 |
public static URL getCodeBase()... |
| 1068 |
|
{ |
| 1069 |
0 |
return (isJS ? jsutil.getCodeBase() : null); |
| 1070 |
|
} |
| 1071 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1072 |
0 |
public static String getUserPath(String subpath)... |
| 1073 |
|
{ |
| 1074 |
0 |
char sep = File.separatorChar; |
| 1075 |
0 |
return System.getProperty("user.home") + sep |
| 1076 |
|
+ subpath.replace('/', sep); |
| 1077 |
|
} |
| 1078 |
|
|
| 1079 |
|
|
| 1080 |
|
|
| 1081 |
|
|
| 1082 |
|
|
| 1083 |
|
@param |
| 1084 |
|
|
| 1085 |
|
@param |
| 1086 |
|
|
| 1087 |
|
@return |
| 1088 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 1089 |
0 |
public static boolean isFileOlderThanThreshold(File file, int noOfDays)... |
| 1090 |
|
{ |
| 1091 |
0 |
if (isJS) |
| 1092 |
|
{ |
| 1093 |
|
|
| 1094 |
|
|
| 1095 |
0 |
return false; |
| 1096 |
|
} |
| 1097 |
0 |
Path filePath = file.toPath(); |
| 1098 |
0 |
BasicFileAttributes attr; |
| 1099 |
0 |
int diffInDays = 0; |
| 1100 |
0 |
try |
| 1101 |
|
{ |
| 1102 |
0 |
attr = Files.readAttributes(filePath, BasicFileAttributes.class); |
| 1103 |
0 |
diffInDays = (int) ((new Date().getTime() |
| 1104 |
|
- attr.lastModifiedTime().toMillis()) |
| 1105 |
|
/ (1000 * 60 * 60 * 24)); |
| 1106 |
|
|
| 1107 |
|
} catch (IOException e) |
| 1108 |
|
{ |
| 1109 |
0 |
e.printStackTrace(); |
| 1110 |
|
} |
| 1111 |
0 |
return noOfDays <= diffInDays; |
| 1112 |
|
} |
| 1113 |
|
|
| 1114 |
|
|
| 1115 |
|
|
| 1116 |
|
|
| 1117 |
|
@param |
| 1118 |
|
|
| 1119 |
|
@param |
| 1120 |
|
|
| 1121 |
|
@return |
| 1122 |
|
|
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 7 |
Complexity Density: 0.78 |
|
| 1123 |
0 |
public static int getLeadingIntegerValue(String input, int failValue)... |
| 1124 |
|
{ |
| 1125 |
0 |
if (input == null) |
| 1126 |
|
{ |
| 1127 |
0 |
return failValue; |
| 1128 |
|
} |
| 1129 |
0 |
if (isJS) |
| 1130 |
|
{ |
| 1131 |
0 |
int val = |
| 1132 |
|
0; |
| 1133 |
0 |
return (val == val + 0 ? val : failValue); |
| 1134 |
|
} |
| 1135 |
|
|
| 1136 |
0 |
String[] parts = input.split("(?=\\D)(?<=\\d)"); |
| 1137 |
0 |
if (parts != null && parts.length > 0 && parts[0].matches("[0-9]+")) |
| 1138 |
|
{ |
| 1139 |
0 |
return Integer.valueOf(parts[0]); |
| 1140 |
|
} |
| 1141 |
0 |
return failValue; |
| 1142 |
|
} |
| 1143 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 1144 |
0 |
public static Map<String, Object> getAppletInfoAsMap()... |
| 1145 |
|
{ |
| 1146 |
0 |
return (isJS ? jsutil.getAppletInfoAsMap() : null); |
| 1147 |
|
} |
| 1148 |
|
|
| 1149 |
|
|
| 1150 |
|
|
| 1151 |
|
|
| 1152 |
|
@param |
| 1153 |
|
|
| 1154 |
|
@return |
| 1155 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 1 |
|
| 1156 |
0 |
public static String getAppID(String frameType)... |
| 1157 |
|
{ |
| 1158 |
|
|
| 1159 |
0 |
String id = Jalview.getInstance().j2sAppletID; |
| 1160 |
0 |
if (id == null) |
| 1161 |
|
{ |
| 1162 |
0 |
Jalview.getInstance().j2sAppletID = id = (isJS |
| 1163 |
|
? (String) jsutil.getAppletAttribute("_id") |
| 1164 |
|
: "jalview"); |
| 1165 |
|
} |
| 1166 |
0 |
return id + (frameType == null ? "" : "-" + frameType); |
| 1167 |
|
} |
| 1168 |
|
|
| 1169 |
|
|
| 1170 |
|
|
| 1171 |
|
|
| 1172 |
|
|
| 1173 |
|
@param |
| 1174 |
|
@return |
| 1175 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
| 1176 |
0 |
public static Locale getLocaleOrNone(Locale loc)... |
| 1177 |
|
{ |
| 1178 |
0 |
return (isJS && loc.getLanguage() == "en" ? new Locale("") : loc); |
| 1179 |
|
} |
| 1180 |
|
|
| 1181 |
|
|
| 1182 |
|
|
| 1183 |
|
|
| 1184 |
|
@param |
| 1185 |
|
@param |
| 1186 |
|
@throws |
| 1187 |
|
|
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 11 |
Complexity Density: 0.65 |
|
| 1188 |
0 |
public static void download(String urlstring, String outfile)... |
| 1189 |
|
throws IOException |
| 1190 |
|
{ |
| 1191 |
0 |
Path temp = null; |
| 1192 |
0 |
try (InputStream is = new URL(urlstring).openStream()) |
| 1193 |
|
{ |
| 1194 |
0 |
if (isJS) |
| 1195 |
|
{ |
| 1196 |
0 |
streamToFile(is, new File(outfile)); |
| 1197 |
0 |
return; |
| 1198 |
|
} |
| 1199 |
0 |
temp = Files.createTempFile(".jalview_", ".tmp"); |
| 1200 |
0 |
try (FileOutputStream fos = new FileOutputStream(temp.toString()); |
| 1201 |
0 |
ReadableByteChannel rbc = Channels.newChannel(is)) |
| 1202 |
|
{ |
| 1203 |
0 |
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); |
| 1204 |
|
|
| 1205 |
|
|
| 1206 |
0 |
Files.copy(temp, Paths.get(outfile), |
| 1207 |
|
StandardCopyOption.REPLACE_EXISTING); |
| 1208 |
|
} |
| 1209 |
|
} catch (IOException e) |
| 1210 |
|
{ |
| 1211 |
0 |
throw e; |
| 1212 |
|
} finally |
| 1213 |
|
{ |
| 1214 |
0 |
try |
| 1215 |
|
{ |
| 1216 |
0 |
if (temp != null) |
| 1217 |
|
{ |
| 1218 |
0 |
Files.deleteIfExists(temp); |
| 1219 |
|
} |
| 1220 |
|
} catch (IOException e) |
| 1221 |
|
{ |
| 1222 |
0 |
System.out.println("Exception while deleting download temp file: " |
| 1223 |
|
+ e.getMessage()); |
| 1224 |
|
} |
| 1225 |
|
} |
| 1226 |
|
} |
| 1227 |
|
} |