Beispiel #1
0
  public static void unzipInteralZip(
      ClassLoader classLoader, String resourcePath, File libDir, boolean debug) {
    if (debug) System.out.println("Extracting " + resourcePath);
    libDir.mkdir();
    URL resource = classLoader.getResource(resourcePath);
    if (resource == null) {
      System.err.println("Could not find the " + resourcePath + " on classpath!");
      System.exit(1);
    }
    class PrintDot extends TimerTask {
      public void run() {
        System.out.print(".");
      }
    }
    Timer timer = new Timer();
    PrintDot task = new PrintDot();
    timer.schedule(task, 0, 2000);

    try {

      BufferedInputStream bis = new BufferedInputStream(resource.openStream());
      JarInputStream jis = new JarInputStream(bis);
      JarEntry je = null;
      while ((je = jis.getNextJarEntry()) != null) {
        java.io.File f =
            new java.io.File(libDir.toString() + java.io.File.separator + je.getName());
        if (je.isDirectory()) {
          f.mkdir();
          continue;
        }
        File parentDir = new File(f.getParent());
        if (!parentDir.exists()) {
          parentDir.mkdir();
        }
        FileOutputStream fileOutStream = new FileOutputStream(f);
        writeStreamTo(jis, fileOutStream, 8 * KB);
        if (f.getPath().endsWith("pack.gz")) {
          unpack(f);
          fileOutStream.close();
          f.delete();
        }
      }

    } catch (Exception exc) {
      task.cancel();
      exc.printStackTrace();
    }
    task.cancel();
  }
Beispiel #2
0
 public static void copyInternalFile(ClassLoader classLoader, String resourcePath, File dest) {
   URL resource = classLoader.getResource(resourcePath);
   try {
     BufferedInputStream bis = new BufferedInputStream(resource.openStream());
     FileOutputStream output = new FileOutputStream(dest);
     writeStreamTo(bis, output, 8 * KB);
     output.close();
   } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }