Ejemplo n.º 1
0
 public static boolean isRunningFromJar() {
   boolean result;
   String home = privateInstance.getHome();
   // is the returned path ending with .jar?
   int lastDot = home.lastIndexOf('.');
   if (lastDot > 0 && lastDot < home.length() - 1) {
     result = home.substring(lastDot).toUpperCase().equals(".JAR");
   } else {
     result = false;
   }
   return result;
 }
Ejemplo n.º 2
0
  private static String getStringFromFileSystem(String resourceIdentifier) {
    StringBuffer result = new StringBuffer();
    try {
      String tt = privateInstance.getHome();
      File in = new File(tt + resourceIdentifier);

      BufferedReader inputReader = new BufferedReader(new FileReader(in));

      String newLine;
      while ((newLine = inputReader.readLine()) != null) {
        result.append(newLine);
      }
      inputReader.close();
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, e);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, e);
    }

    return result.toString();
  }
Ejemplo n.º 3
0
  private static String getStringFromJar(String resourceIdentifier) {
    StringBuilder result = new StringBuilder();
    try {
      JarFile jar = new JarFile(privateInstance.getHome());
      ZipEntry entry = jar.getEntry(resourceIdentifier);

      BufferedReader inputReader =
          new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));

      String newLine;
      while ((newLine = inputReader.readLine()) != null) {
        result.append(newLine);
      }
      inputReader.close();
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, e);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, e);
    }

    return result.toString();
  }
Ejemplo n.º 4
0
  private static void copyFileFromJar(String sourceFileName, File target) {
    try {
      JarFile jar = new JarFile(privateInstance.getHome());
      ZipEntry entry = jar.getEntry(sourceFileName);

      InputStream inputStream = new BufferedInputStream(jar.getInputStream(entry));
      OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target));
      byte[] buffer = new byte[4096];
      for (; ; ) {
        int nBytes = inputStream.read(buffer);
        if (nBytes <= 0) break;
        outputStream.write(buffer, 0, nBytes);
      }
      outputStream.flush();
      outputStream.close();
      inputStream.close();
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, e);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, e);
    }
  }