Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 815   Methods: 37
NCLOC: 443   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IoUtility.java 28,6% 48,3% 45,9% 43,3%
coverage coverage
 1    /* $Id: IoUtility.java,v 1.15 2008/03/27 05:16:29 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.utility;
 19   
 20    import java.io.BufferedOutputStream;
 21    import java.io.BufferedReader;
 22    import java.io.BufferedWriter;
 23    import java.io.ByteArrayInputStream;
 24    import java.io.File;
 25    import java.io.FileInputStream;
 26    import java.io.FileOutputStream;
 27    import java.io.FileReader;
 28    import java.io.FileWriter;
 29    import java.io.IOException;
 30    import java.io.InputStream;
 31    import java.io.InputStreamReader;
 32    import java.io.OutputStreamWriter;
 33    import java.io.Reader;
 34    import java.io.UnsupportedEncodingException;
 35    import java.lang.reflect.Field;
 36    import java.net.MalformedURLException;
 37    import java.net.URL;
 38    import java.nio.charset.Charset;
 39    import java.util.Arrays;
 40    import java.util.Enumeration;
 41    import java.util.Properties;
 42   
 43   
 44    /**
 45    * A collection of useful static methods for input and output.
 46    *
 47    * LATER mime 20070101: use StringBuilder instead of StringBuffer if working under JDK 1.5
 48    *
 49    * @version $Revision: 1.15 $
 50    * @author Michael Meyling
 51    */
 52    public final class IoUtility {
 53   
 54    /**
 55    * Constructor, should never be called.
 56    */
 57  0 private IoUtility() {
 58    // don't call me
 59    }
 60   
 61    /**
 62    * Get default encoding for this system.
 63    *
 64    * @return Default encoding for this system.
 65    */
 66  2 public static String getDefaultEncoding() {
 67  2 return new InputStreamReader(
 68    new ByteArrayInputStream(new byte[0])).getEncoding();
 69    }
 70   
 71   
 72    /**
 73    * Get working Java encoding.
 74    *
 75    * @param encoding Try this encoding.
 76    * @return This is <code>encoding</code> if it is supported. Or an other
 77    * encoding that is supported by this system.
 78    */
 79  0 public static String getWorkingEncoding(final String encoding) {
 80  0 if (encoding != null) {
 81  0 try {
 82  0 if (Charset.isSupported(encoding)
 83    && Charset.forName(encoding).canEncode()) {
 84  0 return encoding;
 85    }
 86    } catch (RuntimeException e) {
 87    // ignore
 88    }
 89    }
 90    // TODO mime 20080309: we must inform someone, but using
 91    // Trace within this class is not wise, because it is used
 92    // before the Trace is initialized.
 93  0 System.err.println("not supported encoding: " + encoding);
 94  0 return "ISO-8859-1"; // every system must support this
 95    }
 96   
 97    /**
 98    * Reads a file and returns the contents as a <code>String</code>.
 99    *
 100    * @param filename Name of the file (could include path).
 101    * @param encoding Take this encoding.
 102    * @return Contents of file.
 103    * @throws IOException File exception occurred.
 104    */
 105  0 public static String loadFile(final String filename, final String encoding)
 106    throws IOException {
 107   
 108  0 final StringBuffer buffer = new StringBuffer();
 109  0 loadFile(filename, buffer, encoding);
 110  0 return buffer.toString();
 111    }
 112   
 113    /**
 114    * Reads contents of a file into a string buffer.
 115    *
 116    * @param filename Name of the file (could include path).
 117    * @param buffer Buffer to fill with file contents.
 118    * @param encoding Take this encoding.
 119    * @throws IOException File exception occurred.
 120    */
 121  0 public static void loadFile(final String filename,
 122    final StringBuffer buffer, final String encoding)
 123    throws IOException {
 124  0 loadFile(new File(filename), buffer, encoding);
 125    }
 126   
 127    /**
 128    * Reads contents of a stream into a string buffer.
 129    *
 130    * @param in This stream will be loaded.
 131    * @param buffer Buffer to fill with file contents.
 132    * @throws IOException File exception occurred.
 133    *
 134    * @deprecated Use {@link #loadReader(Reader, StringBuffer)}.
 135    */
 136  0 public static void loadStream(final InputStream in, final StringBuffer buffer)
 137    throws IOException {
 138   
 139  0 buffer.setLength(0);
 140  0 int c;
 141  0 while ((c = in.read()) >= 0) {
 142  0 buffer.append((char) c);
 143    }
 144    }
 145   
 146    /**
 147    * Reads contents of a {@link Reader} into a string buffer.
 148    *
 149    * @param in This reader will be loaded.
 150    * @param buffer Buffer to fill with file contents.
 151    * @throws IOException File exception occurred.
 152    */
 153  386 public static void loadReader(final Reader in, final StringBuffer buffer)
 154    throws IOException {
 155   
 156  386 buffer.setLength(0);
 157  386 int c;
 158  ? while ((c = in.read()) >= 0) {
 159  5750299 buffer.append((char) c);
 160    }
 161    }
 162   
 163    /**
 164    * Reads contents of a file into a string buffer. Uses default encoding.
 165    *
 166    * @param file This file will be loaded.
 167    * @param buffer Buffer to fill with file contents.
 168    * @throws IOException File exception occurred.
 169    *
 170    * @deprecated Use {@link #loadFile(File, StringBuffer, String)}.
 171    */
 172  0 public static void loadFile(final File file,
 173    final StringBuffer buffer)
 174    throws IOException {
 175   
 176  0 final int size = (int) file.length();
 177  0 buffer.setLength(0);
 178  0 final FileReader in = new FileReader(file);
 179  0 final char[] data = new char[size];
 180  0 int charsread = 0;
 181  0 while (charsread < size) {
 182  0 charsread += in.read(data, charsread, size - charsread);
 183    }
 184  0 in.close();
 185  0 buffer.insert(0, data);
 186    }
 187   
 188    /**
 189    * Reads contents of a file into a string buffer.
 190    *
 191    * @param file This file will be loaded.
 192    * @param buffer Buffer to fill with file contents.
 193    * @param encoding Take this encoding.
 194    * @throws IOException File exception occurred.
 195    */
 196  1 public static void loadFile(final File file,
 197    final StringBuffer buffer, final String encoding)
 198    throws IOException {
 199   
 200  1 buffer.setLength((int) file.length()); // ensure capacity
 201  1 buffer.setLength(0);
 202  1 final InputStreamReader in = new InputStreamReader(new FileInputStream(file), encoding);
 203  1 final char[] data = new char[10 * 1024];
 204   
 205  1 try {
 206  1 int charsread = 0;
 207  ? while (0 < (charsread = in.read(data, 0, data.length))) {
 208  1 buffer.append(data, 0, charsread);
 209    }
 210    } finally {
 211  1 in.close();
 212    }
 213    }
 214   
 215    /**
 216    * Reads a file and returns the contents as a <code>String</code>.
 217    *
 218    * @param file File to load from.
 219    * @return Contents of file.
 220    * @throws IOException File exception occurred.
 221    */
 222  0 public static final byte[] loadFileBinary(final File file) throws IOException {
 223  0 final int size = (int) file.length();
 224  0 final FileInputStream in = new FileInputStream(file);
 225  0 try {
 226  0 final byte[] data = new byte[size];
 227  0 int charsread = 0;
 228  0 while (charsread < size) {
 229  0 final int read = in.read(data, charsread, size - charsread);
 230  0 if (read == -1) {
 231  0 final byte[] result = new byte[charsread];
 232  0 System.arraycopy(data, 0, result, 0, charsread);
 233  0 return result;
 234    }
 235  0 charsread += read;
 236    }
 237  0 in.close();
 238  0 return data;
 239    } finally {
 240  0 close(in);
 241    }
 242    }
 243   
 244   
 245    /**
 246    * Reads contents of an URL into a string buffer. The filling is character set dependent.
 247    * @param url This URL will be loaded.
 248    * @param buffer Buffer to fill with file contents.
 249    * @throws IOException Reading failed.
 250    *
 251    * @deprecated Choose correct encoding.
 252    */
 253  0 public static void loadFile(final URL url, final StringBuffer buffer) throws IOException {
 254  0 InputStream in = null;
 255  0 BufferedReader dis = null;
 256  0 try {
 257  0 in = url.openStream();
 258  0 dis = new BufferedReader(new InputStreamReader(in));
 259  0 int i;
 260  0 while ((i = dis.read()) != -1) {
 261  0 buffer.append((char) i);
 262    }
 263    } finally {
 264  0 close(in);
 265  0 close(dis);
 266    }
 267    }
 268   
 269    /**
 270    * Reads contents of an URL into a string buffer. The filling is character set dependent.
 271    * @param url This URL will be loaded.
 272    * @param buffer Buffer to fill with file contents.
 273    * @param encoding Take this encoding.
 274    * @throws IOException Reading failed.
 275    */
 276  0 public static void loadFile(final URL url, final StringBuffer buffer, final String encoding)
 277    throws IOException {
 278  0 InputStream in = null;
 279  0 BufferedReader dis = null;
 280  0 try {
 281  0 in = url.openStream();
 282  0 dis = new BufferedReader(new InputStreamReader(in, encoding));
 283  0 int i;
 284  0 while ((i = dis.read()) != -1) {
 285  0 buffer.append((char) i);
 286    }
 287    } finally {
 288  0 close(in);
 289  0 close(dis);
 290    }
 291    }
 292   
 293    /**
 294    * Save binary contents of an URL into a file.
 295    *
 296    * @param url This URL will be loaded.
 297    * @param file Write into this file.
 298    * @throws IOException Reading or writing failed.
 299    */
 300  0 public static void saveFileBinary(final URL url, final File file) throws IOException {
 301  0 final InputStream in = url.openStream();
 302  0 final FileOutputStream out = new FileOutputStream(file);
 303   
 304  0 byte[] data = new byte[8 * 1024];
 305  0 int length;
 306   
 307  0 while ((length = in.read(data)) != -1) {
 308  0 out.write(data, 0, length);
 309    }
 310  0 in.close();
 311  0 out.close();
 312    }
 313   
 314    /**
 315    * Convert String into a {@link Reader}.
 316    *
 317    * <a href="http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4094886">
 318    * Bug ID: 4094886</a>
 319    *
 320    * @param data Convert this.
 321    * @return Resulting reader.
 322    */
 323  137 public static final Reader stringToReader(final String data) {
 324  137 try {
 325  137 return new InputStreamReader(new ByteArrayInputStream(data.getBytes("ISO-8859-1")));
 326    } catch (UnsupportedEncodingException e) {
 327  0 throw new RuntimeException(e);
 328    }
 329    }
 330   
 331   
 332    /**
 333    * Saves a <code>String</code> into a file.
 334    *
 335    * @param filename Name of the file (could include path).
 336    * @param text Data to save in the file.
 337    * @throws IOException File exception occurred.
 338    *
 339    * @deprecated Use {@link #saveFile(File, String, String)} that has an encoding.
 340    */
 341  0 public static void saveFile(final String filename, final String text)
 342    throws IOException {
 343  0 saveFile(new File(filename), text);
 344    }
 345   
 346    /**
 347    * Saves a <code>StringBuffer</code> in a file.
 348    *
 349    * @param filename Name of the file (could include path).
 350    * @param text Data to save in the file.
 351    * @throws IOException File exception occurred.
 352    *
 353    * @deprecated Use {@link #saveFile(File, StringBuffer, String)} that has an encoding.
 354    */
 355  0 public static void saveFile(final String filename, final StringBuffer text)
 356    throws IOException {
 357  0 saveFile(new File(filename), text.toString());
 358    }
 359   
 360    /**
 361    * Saves a <code>StringBuffer</code> in a file.
 362    *
 363    * @param file File to save into.
 364    * @param text Data to save in the file.
 365    * @throws IOException File exception occurred.
 366    *
 367    * @deprecated Use {@link #saveFile(File, StringBuffer, String)} that has an encoding
 368    * parameter.
 369    */
 370  0 public static void saveFile(final File file, final StringBuffer text)
 371    throws IOException {
 372  0 saveFile(file, text.toString());
 373    }
 374   
 375    /**
 376    * Saves a <code>String</code> in a file. Uses default encoding.
 377    *
 378    * @param file File to save the data in.
 379    * @param text Data to save in the file.
 380    * @throws IOException File exception occurred.
 381    *
 382    * @deprecated Use {@link #saveFile(File, String, String)} that has an encoding parameter.
 383    */
 384  0 public static void saveFile(final File file, final String text)
 385    throws IOException {
 386  0 BufferedWriter out = new BufferedWriter(
 387    new FileWriter(file));
 388  0 out.write(text);
 389  0 out.close();
 390    }
 391   
 392    /**
 393    * Saves a <code>String</code> in a file.
 394    *
 395    * @param file File to save the data in.
 396    * @param text Data to save in the file.
 397    * @param encoding Use this encoding.
 398    * @throws IOException File exception occurred.
 399    */
 400  0 public static void saveFile(final File file, final StringBuffer text, final String encoding)
 401    throws IOException {
 402  0 saveFile(file, text.toString(), encoding);
 403    }
 404   
 405    /**
 406    * Saves a <code>String</code> in a file.
 407    *
 408    * @param file File to save the data in.
 409    * @param text Data to save in the file.
 410    * @param encoding Use this encoding.
 411    * @throws IOException File exception occurred.
 412    */
 413  1 public static void saveFile(final File file, final String text, final String encoding)
 414    throws IOException {
 415  1 BufferedWriter out = new BufferedWriter(
 416    new OutputStreamWriter(new FileOutputStream(file), encoding));
 417  1 out.write(text);
 418  1 out.close();
 419    }
 420   
 421    /**
 422    * Saves a <code>data</code> in a file.
 423    *
 424    * @param file File to save the data in.
 425    * @param data Data to save in the file.
 426    * @throws IOException File exception occurred.
 427    */
 428  0 public static void saveFileBinary(final File file, final byte[] data)
 429    throws IOException {
 430  0 BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
 431  0 out.write(data);
 432  0 out.close();
 433    }
 434   
 435    /**
 436    * Copies a file to a different location.
 437    *
 438    * @param from Copy source.
 439    * @param to Copy destination.
 440    * @throws IOException File exception occurred.
 441    */
 442  18 public static void copyFile(final File from, final File to)
 443    throws IOException {
 444   
 445  18 if (from.getCanonicalFile().equals(to.getCanonicalFile())) {
 446  0 return;
 447    }
 448  18 FileInputStream in = new FileInputStream(from);
 449  18 FileOutputStream out = new FileOutputStream(to);
 450   
 451  18 byte[] data = new byte[8 * 1024];
 452  18 int length;
 453   
 454  ? while ((length = in.read(data)) != -1) {
 455  153 out.write(data, 0, length);
 456    }
 457  18 in.close();
 458  18 out.close();
 459    }
 460   
 461    /**
 462    * Compare two files.
 463    *
 464    * @param from Compare source.
 465    * @param with Compare with this file.
 466    * @return Is the contents of the two files binary equal?
 467    * @throws IOException File exception occurred.
 468    */
 469  3 public static boolean compareFilesBinary(final File from, final File with)
 470    throws IOException {
 471  3 if (from == null && with == null) {
 472  0 return true;
 473    }
 474  3 if (from == null || with == null) {
 475  0 return false;
 476    }
 477  3 if (from.getAbsoluteFile().equals(with.getAbsoluteFile())) {
 478  0 return true;
 479    }
 480  3 if (from.length() != with.length()) {
 481  0 return false;
 482    }
 483  3 byte[] dataOne = new byte[8 * 1024];
 484  3 byte[] dataTwo = new byte[8 * 1024];
 485  3 int length;
 486   
 487  3 FileInputStream one = null;
 488  3 FileInputStream two = null;
 489  3 try {
 490  3 one = new FileInputStream(from);
 491  3 two = new FileInputStream(with);
 492   
 493  ? while ((length = one.read(dataOne)) != -1) {
 494  36 if (length != two.read(dataTwo)) {
 495  0 return false;
 496    }
 497  36 if (!Arrays.equals(dataOne, dataTwo)) {
 498  0 return false;
 499    }
 500    }
 501  3 return true;
 502    } finally {
 503  3 close(one);
 504  3 close(two);
 505    }
 506    }
 507   
 508    /**
 509    * Delete file directory recursive.
 510    *
 511    * @param directory Directory to delete.
 512    * @param deleteDir Delete directory itself too?
 513    * @return Was deletion successful?
 514    */
 515  1 public static boolean deleteDir(final File directory, final boolean deleteDir) {
 516    // to see if this directory is actually a symbolic link to a directory,
 517    // we want to get its canonical path - that is, we follow the link to
 518    // the file it's actually linked to
 519  1 File candir;
 520  1 try {
 521  1 candir = directory.getCanonicalFile();
 522    } catch (IOException e) {
 523  0 return false;
 524    }
 525   
 526    // a symbolic link has a different canonical path than its actual path,
 527    // unless it's a link to itself
 528  1 if (!candir.equals(directory.getAbsoluteFile())) {
 529    // this file is a symbolic link, and there's no reason for us to
 530    // follow it, because then we might be deleting something outside of
 531    // the directory we were told to delete
 532  0 return false;
 533    }
 534   
 535    // now we go through all of the files and subdirectories in the
 536    // directory and delete them one by one
 537  1 boolean success = true;
 538  1 File[] files = candir.listFiles();
 539  1 if (files != null) {
 540  1 for (int i = 0; i < files.length; i++) {
 541  18 File file = files[i];
 542   
 543    // in case this directory is actually a symbolic link, or it's
 544    // empty, we want to try to delete the link before we try
 545    // anything
 546  18 boolean deleted = file.delete();
 547  18 if (!deleted) {
 548    // deleting the file failed, so maybe it's a non-empty
 549    // directory
 550  0 if (file.isDirectory()) {
 551  0 deleted = deleteDir(file, true);
 552    }
 553   
 554    // otherwise, there's nothing else we can do
 555    }
 556  18 success = success && deleted;
 557    }
 558    }
 559   
 560    // now that we tried to clear the directory out, we can try to delete it
 561    // again
 562  1 if (deleteDir) {
 563  0 return directory.delete();
 564    }
 565  1 return success;
 566    }
 567   
 568    /**
 569    * Print current system properties to System.out.
 570    */
 571  0 public static void printAllSystemProperties() {
 572  0 Properties sysprops = System.getProperties();
 573  0 for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements(); ) {
 574  0 String key = (String) e.nextElement();
 575  0 String value = sysprops.getProperty(key);
 576  0 System.out.println(key + "=" + value);
 577    }
 578    }
 579   
 580    /**
 581    * Get home directory of user.
 582    *
 583    * @return Home directory of user.
 584    */
 585  0 public static File getUserHomeDirectory() {
 586  0 return new File((String) System.getProperties().get("user.home"));
 587    }
 588   
 589    /**
 590    * Convert file in URL.
 591    *
 592    * @param file File.
 593    * @return URL.
 594    */
 595  7589 public static URL toUrl(final File file) {
 596  7589 try {
 597  7589 return file.toURI().toURL();
 598    } catch (MalformedURLException e) { // should only happen if there is a bug in the JDK
 599  0 throw new RuntimeException(e);
 600    }
 601    }
 602   
 603    /**
 604    * Creates necessary parent directories for a file.
 605    *
 606    * @param file File.
 607    */
 608  59 public static void createNecessaryDirectories(final File file) {
 609  59 if (file.getParentFile() != null) {
 610  59 file.getParentFile().mkdirs();
 611    }
 612    }
 613   
 614    /**
 615    * Create relative address from <code>orgin</code> to <code>next</code>.
 616    *
 617    * @param orgin this is the original location
 618    * @param next this should be the next location
 619    * @return relative (or if necessary absolute) file path
 620    */
 621  13 public static final String createRelativePath(final File orgin, final File next) {
 622  13 try {
 623  13 if (orgin.equals(next)) {
 624  0 return "";
 625    }
 626  13 try {
 627  13 String org = orgin.getCanonicalPath().replace('\\', '/');
 628  13 if (!org.endsWith("/")) {
 629  13 org += ('/');
 630    }
 631  13 String nex = next.getCanonicalPath().replace('\\', '/');
 632  13 if (!nex.endsWith("/")) {
 633  13 nex += ('/');
 634    }
 635  13 if (org.equals(nex)) {
 636  0 return "";
 637    }
 638  13 int i = -1; // position of next '/'
 639  13 int j = 0; // position of last '/'
 640  ? while (0 <= (i = org.indexOf("/", j))) {
 641  49 if (i >= 0 && nex.length() > i
 642    && org.substring(j, i).equals(
 643    nex.substring(j, i))) {
 644  47 j = i + 1;
 645    } else {
 646  2 break;
 647    }
 648    }
 649  13 if (j > 0) {
 650  13 i = j;
 651  13 final StringBuffer result = new StringBuffer(nex.length());
 652  ? while (0 <= (i = org.indexOf("/", i))) {
 653  3 i++;
 654  3 result.append("../");
 655    }
 656  13 result.append(nex.substring(j, nex.length() - 1));
 657  13 return result.toString();
 658    }
 659  0 return nex.substring(0, nex.length() - 1);
 660    } catch (RuntimeException e) {
 661  0 return next.toString();
 662    }
 663    } catch (IOException e) {
 664  0 return new File(orgin, next.getPath()).getPath();
 665    }
 666    }
 667   
 668    /**
 669    * Waits until a '\n' was read from System.in.
 670    */
 671  0 public static void waitln() {
 672  0 System.out.println("\n..press <return> to continue");
 673  0 try {
 674  0 (new java.io.BufferedReader(new java.io.InputStreamReader(
 675    System.in))).readLine();
 676    } catch (IOException e) {
 677    // ignore
 678    }
 679    }
 680   
 681    /**
 682    * Closes input stream without exception.
 683    *
 684    * @param in Input stream, maybe <code>null</code>.
 685    */
 686  6 public static void close(final InputStream in) {
 687  6 if (in != null) {
 688  6 try {
 689  6 in.close();
 690    } catch (Exception e) {
 691    // ignore
 692    }
 693    }
 694    }
 695   
 696    /**
 697    * Closes input reader without exception.
 698    *
 699    * @param reader Reader, maybe <code>null</code>.
 700    */
 701  61460 public static void close(final Reader reader) {
 702  61460 if (reader != null) {
 703  61460 try {
 704  61460 reader.close();
 705    } catch (Exception e) {
 706    // ignore
 707    }
 708    }
 709    }
 710   
 711    /**
 712    * Get start directory for application. If this is no Java Webstart version
 713    * the result is <code>new File(".")</code>.
 714    *
 715    * @param application Application name, used for Java Webstart version. Should
 716    * be written in lowercase letters. A "." is automatically appended at
 717    * the beginning.
 718    * @return Start directory for application.
 719    */
 720  4 public static final File getStartDirectory(final String application) {
 721  4 final File startDirectory;
 722  4 if (isWebStarted()) {
 723  0 final String userHomeWS = System.getProperties().get("jnlpx.deployment.user.home")
 724    != null ? (String) System.getProperties().get("jnlpx.deployment.user.home")
 725    : "";
 726  0 final String userHome = System.getProperties().get("user.home") != null
 727    ? (String) System.getProperties().get("user.home") : "";
 728  0 startDirectory = new File(
 729  0 new File((userHomeWS.length() != 0 ? userHomeWS : userHome)), "." + application);
 730    } else {
 731  4 startDirectory = new File(".");
 732    }
 733  4 return startDirectory;
 734    }
 735   
 736    /**
 737    * Was the application started by Java Webstart?
 738    *
 739    * @return Was the application started by Java Webstart.
 740    */
 741  6 public static final boolean isWebStarted() {
 742  6 final String webStart = (String) System.getProperties().get("javawebstart.version");
 743  6 return webStart != null;
 744    }
 745   
 746    /**
 747    * Loads a property file from given URL.
 748    *
 749    * @param url URL to load properties from.
 750    * @return Loaded properties.
 751    * @throws MalformedURLException Invalid URL.
 752    * @throws IOException Reading error.
 753    */
 754  0 public static Properties loadProperties(final URL url)
 755    throws IOException {
 756  0 Properties newprops = new Properties();
 757  0 InputStream in = url.openStream();
 758  0 newprops.load(in);
 759  0 in.close();
 760  0 return newprops;
 761    }
 762   
 763    /**
 764    * This method returns the contents of an object variable (even if it is private).
 765    *
 766    * @param obj Object.
 767    * @param name Variable name
 768    * @return Contents of variable.
 769    */
 770  25335 public static Object getFieldContent(final Object obj, final String name) {
 771  25335 final Field field;
 772  25335 try {
 773  25335 field = obj.getClass().getDeclaredField(name);
 774  25335 field.setAccessible(true);
 775    } catch (SecurityException e) {
 776  0 throw new RuntimeException(e);
 777    } catch (NoSuchFieldException e) {
 778  0 throw new RuntimeException(e);
 779    }
 780  25335 try {
 781  25335 return field.get(obj);
 782    } catch (IllegalArgumentException e) {
 783  0 throw new RuntimeException(e);
 784    } catch (IllegalAccessException e) {
 785  0 throw new RuntimeException(e);
 786    }
 787    }
 788   
 789    /**
 790    * This method sets the contents of an object variable (even if it is private).
 791    *
 792    * @param obj Object.
 793    * @param name Variable name.
 794    * @param value Value to set.
 795    */
 796  57 public static void setFieldContent(final Object obj, final String name, final Object value) {
 797  57 final Field field;
 798  57 try {
 799  57 field = obj.getClass().getDeclaredField(name);
 800  57 field.setAccessible(true);
 801    } catch (SecurityException e) {
 802  0 throw new RuntimeException(e);
 803    } catch (NoSuchFieldException e) {
 804  0 throw new RuntimeException(e);
 805    }
 806  57 try {
 807  57 field.set(obj, value);
 808    } catch (IllegalArgumentException e) {
 809  0 throw new RuntimeException(e);
 810    } catch (IllegalAccessException e) {
 811  0 throw new RuntimeException(e);
 812    }
 813    }
 814   
 815    }