Example #1
1
  /**
   * Load a system library from a stream. Copies the library to a temp file and loads from there.
   *
   * @param libname name of the library (just used in constructing the library name)
   * @param is InputStream pointing to the library
   */
  private void loadLibraryFromStream(String libname, InputStream is) {
    try {
      File tempfile = createTempFile(libname);
      OutputStream os = new FileOutputStream(tempfile);

      logger.debug("tempfile.getPath() = " + tempfile.getPath());

      long savedTime = System.currentTimeMillis();

      // Leo says 8k block size is STANDARD ;)
      byte buf[] = new byte[8192];
      int len;
      while ((len = is.read(buf)) > 0) {
        os.write(buf, 0, len);
      }

      os.flush();
      InputStream lock = new FileInputStream(tempfile);
      os.close();

      double seconds = (double) (System.currentTimeMillis() - savedTime) / 1e3;
      logger.debug("Copying took " + seconds + " seconds.");

      logger.debug("Loading library from " + tempfile.getPath() + ".");
      System.load(tempfile.getPath());

      lock.close();
    } catch (IOException io) {
      logger.error("Could not create the temp file: " + io.toString() + ".\n");
    } catch (UnsatisfiedLinkError ule) {
      logger.error("Couldn't load copied link file: " + ule.toString() + ".\n");
      throw ule;
    }
  }
 static {
   System.load(
       (new File("/home/gathors/proj/v-opencv/FeatureMatching/libs/libopencv_java2412.so"))
           .getAbsolutePath());
   System.load(
       (new File("/home/gathors/proj/v-opencv/FeatureMatching/libs/libopencv_highgui.so"))
           .getAbsolutePath());
 }
Example #3
0
  private static boolean loadLibraryFromAol(String aol) {
    String name = System.mapLibraryName("javalibusb1-" + VERSION);

    String p = "lib/" + aol + "/jni/" + name;

    URL url = libusb1.class.getClassLoader().getResource(p);

    if (url == null) {
      return false;
    }

    File file = new File(url.getPath());

    if (file.canRead()) {
      System.load(file.getAbsolutePath());
      return true;
    }

    OutputStream os = null;
    InputStream is = null;
    try {
      file = File.createTempFile("javalibusb1", "");

      is = url.openStream();
      os = new FileOutputStream(file);

      file.deleteOnExit();

      byte buffer[] = new byte[128 * 1024];

      int read = is.read(buffer);

      while (read > 0) {
        os.write(buffer, 0, read);
        read = is.read(buffer);
      }

      closeSilently(os);
      closeSilently(is);

      System.load(file.getAbsolutePath());

      return true;
    } catch (IOException e) {
      throw new RuntimeException("Unable to load native library", e);
    } finally {
      if (file != null) {
        file.delete();
      }
      closeSilently(os);
      closeSilently(is);
    }
  }
Example #4
0
 private static boolean loadFromPath(String path) {
   try {
     System.load(path);
     return true;
   } catch (Exception e) {
     return false;
   }
 }
 static boolean loadNSPR(String libdir) throws Exception {
   // load NSS softoken dependencies in advance to avoid resolver issues
   try {
     System.load(libdir + System.mapLibraryName(NSPR_PREFIX + "nspr4"));
   } catch (UnsatisfiedLinkError e) {
     // GLIBC problem on older linux-amd64 machines
     if (libdir.contains("linux-amd64")) {
       System.out.println(e);
       System.out.println("NSS does not work on this platform, skipping.");
       return false;
     }
     throw e;
   }
   System.load(libdir + System.mapLibraryName(NSPR_PREFIX + "plc4"));
   System.load(libdir + System.mapLibraryName(NSPR_PREFIX + "plds4"));
   return true;
 }
Example #6
0
 static {
   String path = "";
   try {
     path = new File("Teste13native.dll").getCanonicalPath().toString();
     System.out.println(path);
   } catch (Exception e) {
     System.out.println(e);
   }
   // System.loadLibrary("Teste13native");
   System.load(path);
 }
Example #7
0
 // This is an entry point of a loader and
 // it needs to be thread-safe.
 public void load() {
   if (isLoaded) return;
   try {
     nativeLibFile = findNativeLibrary();
     // Load a specified native library
     System.load(nativeLibFile.getAbsolutePath());
     isLoaded = true;
   } catch (Exception e) {
     throw new RuntimeException();
   }
 }
  // modify by zenki-zha-xxx
  static {
    IEngineService ies = (IEngineService) ERManager.getService(ERManager.ERENGINE_SERVICE);

    String libPath = ies.getConfig().getLibraryPath();
    String soPath = libPath + File.separator + "libDeflatingDecompressor-v3.so";

    try {
      if (libPath.equals(EngineConfig.DEFAULT_LIBRARY_LOCAL)) {
        System.loadLibrary("DeflatingDecompressor-v3");
      } else {
        System.load(soPath);
      }
    } catch (Exception e) {
      Logger.eLog("EREngine", "load libDeflatingDecompressor-v3.so = " + e.getMessage());
    }
  }