示例#1
1
 // load the native library unowinreg.dll
 // FIXME: drop dependency on unowinreg.dll and use com.ice.jni.registry instead
 static {
   try {
     ClassLoader cl = WinRegKey.class.getClassLoader();
     InputStream is = cl.getResourceAsStream("win/unowinreg.dll");
     if (is != null) {
       // generate a temporary name for lib file and write to temp
       // location
       BufferedInputStream istream = new BufferedInputStream(is);
       File libfile = File.createTempFile("unowinreg", ".dll");
       libfile.deleteOnExit(); // ensure deletion
       BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(libfile));
       int bsize = 2048;
       int n = 0;
       byte[] buffer = new byte[bsize];
       while ((n = istream.read(buffer, 0, bsize)) != -1) {
         ostream.write(buffer, 0, n);
       }
       istream.close();
       ostream.close();
       // load library
       System.load(libfile.getPath());
     } else {
       // If the library cannot be found as a class loader resource,
       // try the global System.loadLibrary(). The JVM will look for
       // it in the java.library.path.
       System.loadLibrary("unowinreg");
     }
   } catch (java.lang.Exception e) {
     System.err.println(WinRegKey.class.getName() + " loading of native library failed!" + e);
   }
 }
示例#2
1
文件: D.java 项目: vongosling/btrace
 private static void loadBTraceLibrary(final ClassLoader loader) {
   boolean isSolaris = System.getProperty("os.name").equals("SunOS");
   if (isSolaris) {
     try {
       System.loadLibrary("btrace");
       dtraceEnabled = true;
     } catch (LinkageError le) {
       if (loader == null || loader.getResource("net/java/btrace") == null) {
         System.err.println("cannot load libbtrace.so, will miss DTrace probes from BTrace");
         return;
       }
       String path = loader.getResource("net/java/btrace").toString();
       path = path.substring(0, path.indexOf("!"));
       path = path.substring("jar:".length(), path.lastIndexOf('/'));
       String cpu = System.getProperty("os.arch");
       if (cpu.equals("x86")) {
         cpu = "i386";
       }
       path += "/" + cpu + "/libbtrace.so";
       try {
         path = new File(new URI(path)).getAbsolutePath();
       } catch (RuntimeException re) {
         throw re;
       } catch (Exception e) {
         throw new RuntimeException(e);
       }
       try {
         System.load(path);
         dtraceEnabled = true;
       } catch (LinkageError le1) {
         System.err.println("cannot load libbtrace.so, will miss DTrace probes from BTrace");
       }
     }
   }
 }
示例#3
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());
 }
 static {
   try {
     if (CrossSystem.isWindows()) {
       System.load(JDUtilities.getResourceFile("libs/rtmp.dll").getAbsolutePath());
     } else if (CrossSystem.isLinux()) {
       System.load(JDUtilities.getResourceFile("libs/librtmp.so").getAbsolutePath());
     }
   } catch (Exception e) {
     System.out.println("Error: " + e);
   }
 }
示例#6
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);
    }
  }
  private static void loadLibrary() {
    // load libjettysetuid.so ${jetty.libsetuid.path}
    try {
      if (System.getProperty("jetty.libsetuid.path") != null) {
        File lib = new File(System.getProperty("jetty.libsetuid.path"));
        if (lib.exists()) {
          System.load(lib.getCanonicalPath());
        }
        return;
      }

    } catch (Throwable e) {
      // Ignorable if there is another way to find the lib
    }

    try {
      System.loadLibrary("libsetuid");
      return;
    } catch (Throwable e) {
      // Ignorable if ther eis another way to find the lib
    }

    // try to load from usual path @ jetty.home/lib/ext
    try {
      if (System.getProperty("jetty.home") != null) {
        File lib = new File(System.getProperty("jetty.home") + "/lib/ext/libsetuid.so");
        if (lib.exists()) {
          System.load(lib.getCanonicalPath());
        }
        return;
      }

    } catch (Throwable e) {

    }

    // try to load from jetty.lib where rpm puts this file
    try {
      if (System.getProperty("jetty.lib") != null) {
        File lib = new File(System.getProperty("jetty.lib") + "/libsetuid.so");
        if (lib.exists()) {
          System.load(lib.getCanonicalPath());
        }
        return;
      }

    } catch (Throwable e) {
    }

    System.err.println("Error: libsetuid.so could not be found");
  }
  public void robotInit() {
    System.load("/usr/local/lib/lib_OpenCV/java/libopencv_java2410.so");
    Definitions.initPeripherals();
    //    	frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
    //
    //    	try {
    //    		front = NIVision.IMAQdxOpenCamera("cam1",
    // NIVision.IMAQdxCameraControlMode.CameraControlModeController);
    //    	}
    //    	catch (Exception e){
    //    		frontfailed = true;
    //    	}
    //    	try {
    //    	back = NIVision.IMAQdxOpenCamera("cam0",
    // NIVision.IMAQdxCameraControlMode.CameraControlModeController);
    //    	}
    //    	catch (Exception e){
    //    		backfailed = true;
    //    	}
    //    	if (!backfailed){
    //    		currsession = back;
    //    		NIVision.IMAQdxConfigureGrab(currsession);
    //    	}
    //    	else if (!frontfailed){
    //    		currsession = front;
    //    		NIVision.IMAQdxConfigureGrab(currsession);
    //    	}
    //    	else {
    //    		System.out.println("No cameras");
    //    	}

  }
示例#9
0
  // 加载提取出来的SO文件
  static boolean _loadUnzipSo(String libname, int version) {
    boolean initSuc = false;
    try {

      // 尝试libwebp.so
      Log.w(LOGTAG, "init my so libray:" + libname);
      if (isExist(libname, version)) {
        System.load(_targetSoFile(libname, version));
      } else {
        Log.e(LOGTAG, "so not in fetched place:" + libname);
        TBS.Ext.commitEvent(EventID_SO_INIT, "so not in fetched place:" + libname);
      }
      initSuc = true;
    } catch (Exception e) {
      initSuc = false;
      Log.e(LOGTAG, "init so failed library:" + libname + ",e=" + e.getMessage());
      e.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e.getMessage());
    } catch (java.lang.UnsatisfiedLinkError e2) {
      initSuc = false;
      Log.e(LOGTAG, "init so failed failed(UnsatisfiedLinkError):" + e2.getMessage());
      e2.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e2.getMessage());

    } catch (java.lang.Error e3) {
      initSuc = false;
      e3.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e3.getMessage());
    }
    return initSuc;
  }
示例#10
0
  /**
   * Loads a native library from a file.
   *
   * @param directory the directory in which the library is supposed to be located
   * @param filename filename of the library to be loaded
   * @throws IOException thrown if an internal native library cannot be extracted
   */
  public static void loadLibraryFromFile(final String directory, final String filename)
      throws IOException {

    final String libraryPath = directory + File.separator + filename;

    synchronized (loadedLibrarySet) {
      final File outputFile = new File(directory, filename);
      if (!outputFile.exists()) {

        // Try to extract the library from the system resources
        final ClassLoader cl = ClassLoader.getSystemClassLoader();
        final InputStream in = cl.getResourceAsStream(JAR_PREFIX + filename);
        if (in == null) {
          throw new IOException(
              "Unable to extract native library " + filename + " to " + directory);
        }

        final OutputStream out = new FileOutputStream(outputFile);
        copy(in, out);
      }

      System.load(libraryPath);
      loadedLibrarySet.add(filename);
    }
  }
 /** Static constructor */
 static {
   try {
     System.load("libantradio.so");
   } catch (Exception e) {
     Log.e("JANT", "Exception during nativeJANT_ClassInitNative (" + e.toString() + ")");
   }
 }
示例#12
0
  @Override
  public boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) {
    try {
      for (Entry<String, String> nativeEntry : platformNativeIndex.entrySet()) {
        if (nativeEntry.getKey().contains(libname)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Loading mapped entry: [{}] [{}] [{}]",
                libname,
                nativeEntry.getKey(),
                nativeEntry.getValue());
          }
          File nativeLibCopy =
              extractJarEntry(
                  nativeEntry.getValue(),
                  nativeEntry.getKey(),
                  System.getProperty(JAVA_TMP_DIR),
                  String.format("%s.jni", libname));
          System.load(nativeLibCopy.getAbsolutePath());
          return true;
        }
      }
    } catch (Exception e) {
      log.error("Unable to load native library [{}] - {}", libname, e);
    }

    if (log.isDebugEnabled()) {
      log.debug("No mapped library match for [{}]", libname);
    }
    return false;
  }
示例#13
0
  public static void load() {
    libraryNames = PlatformDependencies.currentLibraryNames;
    libraryExtensions = PlatformDependencies.currentLibraryExtension;
    String dir = "";
    try {
      dir = PropertiesBean.getProperty(PropertiesNames.RESOURCES_DIR /*"dirs.resources"*/);
    } catch (NoSuchPropertyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      logger.warning(e.toString());
      dir = ".\\resources";
    }

    for (int i = 0; i < libraryNames.length; ++i) {
      String latestLib = getLatestFileName(dir, libraryNames[i], libraryExtensions);
      try {
        System.load(latestLib);
        logger.fine("loaded " + latestLib); // debug
      } catch (Throwable e1) {
        logger.warning("Error While loading library " + latestLib + ": " + e1.toString());
      }
    }

    //        // initialize ResourceManager with resources from resources directory
    //        ResourceManager.addResources(dir);

  }
示例#14
0
  static {
    /* An alternate library name can be specified via a property. */
    String libname;
    int v_major, v_minor, v_patch;

    v_major = DbConstants.DB_VERSION_MAJOR;
    v_minor = DbConstants.DB_VERSION_MINOR;
    v_patch = DbConstants.DB_VERSION_PATCH;

    if ((libname = System.getProperty("sleepycat.db.libfile")) != null) System.load(libname);
    else if ((libname = System.getProperty("sleepycat.db.libname")) != null)
      System.loadLibrary(libname);
    else {
      String os = System.getProperty("os.name");
      if (os != null && os.startsWith("Windows")) {
        /*
         * On Windows, library name is something like
         * "libdb_java42.dll" or "libdb_java42d.dll".
         */
        libname = "libdb_java" + v_major + v_minor;

        try {
          System.loadLibrary(libname);
        } catch (UnsatisfiedLinkError e) {
          try {
            libname += "d";
            System.loadLibrary(libname);
          } catch (UnsatisfiedLinkError e2) {
            throw e;
          }
        }
      } else {
        /*
         * On UNIX, library name is something like
         * "libdb_java-3.0.so".
         */
        System.loadLibrary("db_java-" + v_major + "." + v_minor);
      }
    }

    initialize();

    if (DbEnv_get_version_major() != v_major
        || DbEnv_get_version_minor() != v_minor
        || DbEnv_get_version_patch() != v_patch)
      throw new RuntimeException(
          "Berkeley DB library version "
              + DbEnv_get_version_major()
              + "."
              + DbEnv_get_version_minor()
              + "."
              + DbEnv_get_version_patch()
              + " doesn't match Java class library version "
              + v_major
              + "."
              + v_minor
              + "."
              + v_patch);
  }
示例#15
0
 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;
 }
示例#16
0
 private static boolean loadFromPath(String path) {
   try {
     System.load(path);
     return true;
   } catch (Exception e) {
     return false;
   }
 }
示例#17
0
 static {
   // System.loadLibrary("SocialNetwork");
   // Linux hack, if you can't get your library
   // path set in your environment:
   System.load("F:/Devesh/Done in 2nd year/WebServices/SocioNetWS/native/SocialNetwork.dll");
   ServerRunner.mainCall();
   System.out.println("Library Loaded");
 }
 /**
  * Utilizes the regular system call to attempt to load a native library. If a failure occurs, then
  * the function extracts native .so library out of the app's APK and attempts to load it.
  *
  * <p><strong>Note: This is a synchronous operation</strong>
  */
 @SuppressLint("UnsafeDynamicallyLoadedCode") // intended fallback of System#loadLibrary()
 static void loadLibrary(Context context, final String library) {
   final String libName = System.mapLibraryName(library);
   synchronized (ReLinker.class) {
     final File workaroundFile = unpackLibrary(context, libName);
     System.load(workaroundFile.getAbsolutePath());
   }
 }
示例#19
0
 /** Puts library to temp dir and loads to memory */
 private static void loadLib(String name) {
   Path sourcePath = Paths.get(LIBPATH, name);
   try {
     Path libPath = Files.copy(sourcePath, tempPath, StandardCopyOption.REPLACE_EXISTING);
     System.load(libPath.toString());
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#20
0
  @Before
  public void setup() {

    System.load("C:/Users/Grant Dawson/Documents/opencv/build/java/x64/opencv_java246.dll");

    this.mockMvc = webAppContextSetup(this.wac).build();

    Stripe.apiKey = "sk_test_cAefVlVMmXfcSKMZOKLhielX";
  }
 // Code for loading the windows native dll
 static {
   try {
     File libFile = DllManager.findLibFile();
     System.load(libFile.getAbsolutePath());
     DllManager.cleanupTempFiles();
   } catch (IOException e) {
     throw new RuntimeException("Error loading dll" + e.getMessage(), e);
   }
 }
示例#22
0
  /**
   * Loads library from current JAR archive
   *
   * <p>The file from JAR is copied into system temporary directory and then loaded. The temporary
   * file is deleted after exiting. Method uses String as filename because the pathname is
   * "abstract", not system-dependent.
   *
   * @param filename The filename inside JAR as absolute path (beginning with '/'), e.g.
   *     /package/File.ext
   * @throws IOException If temporary file creation or read/write operation fails
   * @throws IllegalArgumentException If source file (param path) does not exist
   * @throws IllegalArgumentException If the path is not absolute or if the filename is shorter than
   *     three characters (restriction of {
   * @see File#createTempFile(java.lang.String, java.lang.String)}).
   */
  public static void loadLibraryFromJar(String path) throws IOException {

    if (!path.startsWith("/")) {
      throw new IllegalArgumentException("The path to be absolute (start with '/').");
    }

    // Obtain filename from path
    String[] parts = path.split("/");
    String filename = (parts.length > 1) ? parts[parts.length - 1] : null;

    // Split filename to prexif and suffix (extension)
    String prefix = "";
    String suffix = null;
    if (filename != null) {
      parts = filename.split("\\.", 2);
      prefix = parts[0];
      suffix = (parts.length > 1) ? "." + parts[parts.length - 1] : null; // Thanks, davs! :-)
    }

    // Check if the filename is okay
    if (filename == null || prefix.length() < 3) {
      throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
    }

    // Prepare temporary file
    File temp = File.createTempFile(prefix, suffix);
    temp.deleteOnExit();

    if (!temp.exists()) {
      throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist.");
    }

    // Prepare buffer for data copying
    byte[] buffer = new byte[1024];
    int readBytes;

    // Open and check input stream
    InputStream is = NativeUtils.class.getResourceAsStream(path);
    if (is == null) {
      throw new FileNotFoundException("File " + path + " was not found inside JAR.");
    }

    // Open output stream and copy data between source file in JAR and the temporary file
    OutputStream os = new FileOutputStream(temp);
    try {
      while ((readBytes = is.read(buffer)) != -1) {
        os.write(buffer, 0, readBytes);
      }
    } finally {
      // If read/write fails, close streams safely before throwing an exception
      os.close();
      is.close();
    }

    // Finally, load the library
    System.load(temp.getAbsolutePath());
  }
示例#23
0
 public static void loadDclassSharedObject() throws IOException {
   try {
     if (OS.contains("mac")) {
       System.load("/usr/local/lib/libdclassjni.0.dylib");
     } else if (OS.contains("nix") || OS.contains("nux") || OS.contains("aix")) {
       System.load("/usr/lib/libdclassjni.so");
     } else {
       System.err.println("OS not supported.");
       System.exit(-1);
     }
   } catch (UnsatisfiedLinkError e) {
     File f = new File("/usr/lib/libdclassjni.so");
     System.err.println("/usr/lib/libdclassjni.so exists: " + f.exists());
     System.err.println("/usr/lib/libdclassjni.so is readable: " + f.canRead());
     System.err.println("Native code library failed to load.\n" + e);
     e.printStackTrace();
   }
 }
示例#24
0
  private static boolean loadEmbeddedLibrary() {

    boolean usingEmbedded = false;

    // attempt to locate embedded native library within JAR at following location:
    // /NATIVE/${os.arch}/${os.name}/libjzmq.[so|dylib|dll]
    final String[] allowedExtensions = new String[] {"so", "dylib", "dll"};
    final StringBuilder url = new StringBuilder();
    url.append("/NATIVE/");
    url.append(getCurrentPlatformIdentifier());
    url.append("/libjzmq.");
    URL nativeLibraryUrl = null;
    String ext = null;
    // loop through extensions, stopping after finding first one
    for (String attempt : allowedExtensions) {
      ext = attempt;
      nativeLibraryUrl = ZMQ.class.getResource(url.toString() + ext);
      if (nativeLibraryUrl != null) {
        break;
      }
    }

    if (nativeLibraryUrl != null) {

      // native library found within JAR, extract and load
      try {
        final File tmpDir = getTempDirectory();
        final File libfile = File.createTempFile("libjzmq-", "." + ext, tmpDir);
        libfile.deleteOnExit(); // just in case

        final InputStream in = nativeLibraryUrl.openStream();
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(libfile));

        int len = 0;
        final byte[] buffer = new byte[8192];
        while ((len = in.read(buffer)) > -1) out.write(buffer, 0, len);
        out.close();
        in.close();

        System.load(libfile.getAbsolutePath());

        libfile.delete();

        usingEmbedded = true;

      } catch (final IOException x) {
        // mission failed, do nothing
      } catch (final RuntimeException r) {
        // mission failed, do nothing
      } catch (final UnsatisfiedLinkError l) {
        // mission failed, do nothing
      }
    } // nativeLibraryUrl exists

    return usingEmbedded;
  }
  public static void main(String[] args) {
    // load c++ library
    String sharedObjPath = "/home/jave/workspace/BlackadderJNIWrapper/libs/";
    // System.load(sharedObjPath + "libgnustl_shared.so");
    System.load(sharedObjPath + "libblackadder.so");
    BAWrapper.configureObjectFile(sharedObjPath + "libuk_ac_cam_cl_xf214_blackadderWrapper.so");
    wrapper = BAWrapper.getWrapper();

    startEventHandler();
    pubTest();
  }
示例#26
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();
   }
 }
示例#27
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);
 }
 static {
   String LIB_ROOT = Vitamio.getLibraryPath();
   try {
     Log.i("LIB ROOT: %s", LIB_ROOT);
     System.load(LIB_ROOT + "libstlport_shared.so");
     System.load(LIB_ROOT + "libvplayer.so");
     loadFFmpeg_native(LIB_ROOT + "libffmpeg.so");
     boolean vvo_loaded = false;
     if (Build.VERSION.SDK_INT > 8) vvo_loaded = loadVVO_native(LIB_ROOT + "libvvo.9.so");
     else if (Build.VERSION.SDK_INT > 7) vvo_loaded = loadVVO_native(LIB_ROOT + "libvvo.8.so");
     else vvo_loaded = loadVVO_native(LIB_ROOT + "libvvo.7.so");
     if (!vvo_loaded) {
       vvo_loaded = loadVVO_native(LIB_ROOT + "libvvo.j.so");
       Log.d("FALLBACK TO VVO JNI " + vvo_loaded);
     }
     loadVAO_native(LIB_ROOT + "libvao.0.so");
   } catch (java.lang.UnsatisfiedLinkError e) {
     Log.e("Error loading libs", e);
   }
 }
示例#29
0
  /**
   * Load the the versioned libs
   *
   * @return void
   */
  private void createLibsAliases() {
    // fill this array with the name of the lib and the needed versioned
    // name
    String[][] libraries = {{"libproj.so", "libproj.so.0"}
      // ,{"libgdal.so","libgdal.so.2"}
    };

    for (int i = 0; i < libraries.length; i++) {
      File lib = new File("/data/data/org.qgis.qgis/lib/" + libraries[i][0]);
      String aliasName = libraries[i][1];
      String aliasPath = getFilesDir() + "/" + aliasName;

      try {
        File alias = new File(aliasPath);
        if (!alias.exists()) {
          try {
            String str = "ln -s " + lib.getAbsolutePath() + " " + aliasPath;
            Process process = Runtime.getRuntime().exec(str);
            int res = process.waitFor();
            process.destroy();
            if (res != 0) {
              Log.i(QtTAG, "Can't use symlinks, copying '" + aliasName + " to " + aliasPath);
              try {

                BufferedOutputStream out =
                    new BufferedOutputStream(openFileOutput(aliasName, MODE_PRIVATE));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(lib));
                byte[] buff = new byte[32 * 1024];
                int len;
                while ((len = in.read(buff)) > 0) {
                  out.write(buff, 0, len);
                }
                out.flush();
                out.close();
              } catch (IOException e) {
                Log.w("ExternalStorage", "Error writing " + aliasPath, e);
              }
            } else {
              Log.i(QtTAG, "Symlinked '" + lib.getAbsolutePath() + "' to '" + aliasPath + "'");
            }

          } catch (SecurityException e) {
            Log.i(QtTAG, "Can't symlink '" + aliasName + "'", e);
          }
        }
        Log.i(QtTAG, "Loading '" + aliasPath + "'");
        System.load(aliasPath);
      } catch (SecurityException e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      } catch (Exception e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      }
    }
  }
示例#30
0
 public static void initialize() {
   if (!_initialized) {
     try {
       System.load("/usr/lib/sax/plugins/SaX.so");
     } catch (UnsatisfiedLinkError e) {
       System.err.println("Native code library failed to load\n" + e);
       System.exit(1);
     }
     _initialized = true;
   }
 }