Пример #1
1
  public void addExtension(Class<?> loadResourcesUsing, String loadFrom) throws IOException {
    // Is loadFrom a file?
    File file = new File(loadFrom);
    if (file.exists()) {
      addExtension(file);
      return;
    }

    // Try and load it from the classpath
    InputStream resource = loadResourcesUsing.getResourceAsStream(loadFrom);
    if (resource == null && !loadFrom.startsWith("/")) {
      resource = loadResourcesUsing.getResourceAsStream("/" + loadFrom);
    }
    if (resource == null) {
      resource = FirefoxProfile.class.getResourceAsStream(loadFrom);
    }
    if (resource == null && !loadFrom.startsWith("/")) {
      resource = FirefoxProfile.class.getResourceAsStream("/" + loadFrom);
    }
    if (resource == null) {
      throw new FileNotFoundException("Cannot locate resource with name: " + loadFrom);
    }

    File root;
    if (FileHandler.isZipped(loadFrom)) {
      root = FileHandler.unzip(resource);
    } else {
      throw new RuntimeException("Will only install zipped extensions for now");
    }

    addExtension(root);
  }
Пример #2
0
 private File obtainRootDirectory(File extensionToInstall) throws IOException {
   File root = extensionToInstall;
   if (!extensionToInstall.isDirectory()) {
     BufferedInputStream bis = new BufferedInputStream(new FileInputStream(extensionToInstall));
     try {
       root = FileHandler.unzip(bis);
     } finally {
       bis.close();
     }
   }
   return root;
 }