Example usage for java.lang System load

List of usage examples for java.lang System load

Introduction

In this page you can find the example usage for java.lang System load.

Prototype

@CallerSensitive
public static void load(String filename) 

Source Link

Document

Loads the native library specified by the filename argument.

Usage

From source file:org.caleydo.core.view.opengl.layout2.internal.SandBoxLibraryLoader.java

/**
 * convention for custom library loader//w  w w .  j a va  2s .  c o m
 */
public static void loadLibrary(String libName) throws IOException {
    File file = toTemporaryFile(libName);
    // use System.load as it supports absolute file paths
    System.load(file.getAbsolutePath());
}

From source file:org.ncic.bioinfo.sparkseq.algorithms.adapters.BwaMemAdapter.java

private static BwaIndex getBwaIndexInstance(String bwaJNILibPath, String referencePath) throws IOException {
    if (bwaIndexInstance == null) {
        synchronized (BwaMemAdapter.class) {
            if (bwaIndexInstance == null) {
                System.load(bwaJNILibPath);
                bwaIndexInstance = new BwaIndex(new File(referencePath));
            }/* w w w  .  j a  v  a 2  s  .  c om*/
        }
    }
    return bwaIndexInstance;
}

From source file:fr.jetoile.hadoopunit.HadoopUtils.java

public static void setHadoopHome() {

    // Set hadoop.home.dir to point to the windows lib dir
    if (System.getProperty("os.name").startsWith("Windows")) {

        if (StringUtils.isEmpty(System.getenv("HADOOP_HOME"))) {

            try {
                configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE);
            } catch (ConfigurationException e) {
                LOG.error("unable to load {}", HadoopUnitConfig.DEFAULT_PROPS_FILE, e);
            }//from   ww w  .j  av a 2s .c  o  m

            String hadoop_home = configuration.getString("HADOOP_HOME");

            LOG.info("Setting hadoop.home.dir: {}", hadoop_home);
            if (hadoop_home == null) {
                LOG.error("HADOOP_HOME should be set or informed into hadoop-unit-default.properties");
                System.exit(-1);
            } else {
                System.setProperty("HADOOP_HOME", hadoop_home);
            }

        } else {
            System.setProperty("HADOOP_HOME", System.getenv("HADOOP_HOME"));
        }

        String windowsLibDir = System.getenv("HADOOP_HOME");

        LOG.info("WINDOWS: Setting hadoop.home.dir: {}", windowsLibDir);
        System.setProperty("hadoop.home.dir", windowsLibDir);
        System.load(new File(windowsLibDir + Path.SEPARATOR + "bin" + Path.SEPARATOR + "hadoop.dll")
                .getAbsolutePath());
        System.load(new File(windowsLibDir + Path.SEPARATOR + "bin" + Path.SEPARATOR + "hdfs.dll")
                .getAbsolutePath());
    }
}

From source file:ml.dmlc.xgboost4j.java.NativeLibLoader.java

/**
 * Loads library from current JAR archive
 * <p/>/*from   w  w  w  . jav a2  s  .c  om*/
 * 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.
 * <p/>
 * The restrictions of {@link File#createTempFile(java.lang.String, java.lang.String)} apply to
 * {@code path}.
 *
 * @param path 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
 */
private static void loadLibraryFromJar(String path) throws IOException, IllegalArgumentException {
    String temp = createTempFileFromResource(path);
    // Finally, load the library
    System.load(temp);
}

From source file:com.picklecode.popflix.App.java

private static void loadLib(String name) {

    try {//from   w  w  w .j a  v a  2s.  c o  m

        if (isWindows()) {
            name = name.substring("lib".length());
        }

        String ext = getExtension();
        name = name + ext;

        LOG.info(System.getProperty("os.arch"));
        LOG.info(System.getProperty("os.name"));
        Path tmp = Files.createTempDirectory("popflix");
        setLibraryPath(tmp.toString());
        LOG.info(tmp.toString() + "/" + name);
        File fileOut = new File(tmp.toString() + "/" + name);

        LOG.info(System.getProperty("java.library.path"));

        System.out.println("/lib/" + getFolder() + "/" + name);
        InputStream in = Popflix.class.getResourceAsStream("/lib/" + getFolder() + "/" + name);
        if (in != null) {

            OutputStream out = FileUtils.openOutputStream(fileOut);
            IOUtils.copy(in, out);
            in.close();
            out.close();

        }
        System.load(fileOut.getAbsolutePath());//loading goes here
    } catch (Exception e) {
        LOG.error(e.getMessage());
        System.exit(-1);
    }
}

From source file:org.esa.s2tbx.dataio.NativeLibraryLoader.java

/**
 * Loads library either from the current JAR archive, or from file system
 * <p>/*from  ww  w.  j a  v a 2s .  c om*/
 * The file from JAR is copied into system temporary directory and then loaded.
 *
 * @param path          The path from which the load is attempted
 * @param libraryName   The name of the library to be loaded (without extension)
 * @throws IOException              If temporary file creation or read/write operation fails
 */
public static void loadLibrary(String path, String libraryName) throws IOException {
    path = URLDecoder.decode(path, "UTF-8");
    String libPath = "/lib/" + NativeLibraryLoader.getOSFamily() + "/" + System.mapLibraryName(libraryName);
    if (path.contains(".jar!")) {
        try (InputStream in = NativeLibraryLoader.class.getResourceAsStream(libPath)) {
            File fileOut = new File(System.getProperty("java.io.tmpdir"), libPath);
            try (OutputStream out = FileUtils.openOutputStream(fileOut)) {
                IOUtils.copy(in, out);
            }
            path = fileOut.getAbsolutePath();
        }
    } else {
        path = new File(path, libPath).getAbsolutePath();
    }
    System.load(path);
}

From source file:jd.ide.intellij.JavaDecompiler.java

private void loadLibrary(String pluginPath, String libPath) {
    try {/*w  w  w.j  a v a  2s . c  o m*/
        System.load(libPath);
    } catch (Exception e) {
        throw new IllegalStateException("Something got wrong when loading the Java Decompiler native lib, "
                + "\nlookup path : " + libPath + "\nplugin path : " + pluginPath, e);
    }
}

From source file:eu.mihosoft.vfxwebkit.DemoApplication.java

@Override
public void start(Stage primaryStage) {
    Path tmpFile = null;//from w ww  . j a v  a2 s.com
    try {
        tmpFile = Files.createTempDirectory("eu.mihosoft.vfxwebkit");
    } catch (IOException ex) {
        Logger.getLogger(DemoApplication.class.getName()).log(Level.SEVERE, null, ex);
        System.exit(1);
    }

    try {
        FileUtils.copyDirectory(new File("src/main/resources/eu/mihosoft/vfxwebkit/"), tmpFile.toFile());
        //            FileUtils.copyDirectory(
        //                    new File("/Users/miho/Qt/qt/5.5/clang_64/lib/"),
        //                    new File(tmpFile.toFile(),"native/osx/"));
    } catch (IOException ex) {
        Logger.getLogger(DemoApplication.class.getName()).log(Level.SEVERE, null, ex);
    }

    File libraryPath = new File(tmpFile.toFile(), "native/osx/libvfxwebkit.1.0.0.dylib");

    System.load(libraryPath.getAbsolutePath());

    //        new Thread(()->{NativeBinding.INSTANCE.init();}).start();

    //        NativeBinding.INSTANCE.init();

    VFXWebNode webView = VFXWebNode.newInstance(VFXWebNode.NodeType.JFX_DIRECT_BUFFER);
    //        webView.getEngine().load("http://learningwebgl.com/lessons/lesson04/index.html");

    Window w = new Window("Qt WebKit & WebGL inside JavaFX");
    w.setPrefSize(600, 440);

    w.getContentPane().getChildren().add(webView.getNode());

    //        Window w2 = new Window("JavaFX WebView");
    //        w2.setLayoutX(620);
    //        w2.setPrefSize(600, 440);
    //        
    //        WebView fxview = new WebView();
    //        fxview.getEngine().load("http://learningwebgl.com/lessons/lesson04/index.html");
    //        
    //        w2.getContentPane().getChildren().add(fxview);

    Pane root = new Pane();
    root.getChildren().add(w);

    Scene scene = new Scene(root, 1280, 1024);

    primaryStage.setTitle("Hello Native Qt, hello WebGL!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:org.mwc.cmap.media.xuggle.NativeLibrariesLoader.java

public static void loadBundledXuggler(File nativeLibrariesDirectory, Bundle bundle) throws IOException {
    nativeLibrariesDirectory.mkdirs();//w w  w.ja va2s  .  c  om
    cleanDirectory(nativeLibrariesDirectory);
    String nativePath = null;
    char versionSeparator = '-';
    if (OSUtils.WIN) {
        nativePath = OSUtils.IS_64BIT ? "/native/win64/" : "/native/win32/";
    }
    if (OSUtils.MAC && OSUtils.IS_64BIT) {
        nativePath = "/native/mac64/";
        versionSeparator = '.';
    }
    if (nativePath == null) {
        // we don't have bundled libraries for this os
        return;
    }
    InputStream loadOrderStream = bundle.getResource(nativePath + "load-order").openStream();
    try {
        List<String> loadOrder = IOUtils.readLines(loadOrderStream);
        for (String libraryToLoad : loadOrder) {
            libraryToLoad = libraryToLoad.trim();
            if (libraryToLoad.isEmpty()) {
                continue;
            }
            File libraryFile = new File(nativeLibrariesDirectory, libraryToLoad);
            FileUtils.copyURLToFile(bundle.getResource(nativePath + libraryToLoad), libraryFile);
            String libraryName = libraryToLoad.substring(0, libraryToLoad.lastIndexOf('.'));
            if (libraryName.startsWith("lib")) {
                libraryName = libraryName.substring(3);
            }
            int indexOfSeparator = libraryName.lastIndexOf(versionSeparator);
            long libraryVersion = 0;
            try {
                libraryVersion = Long.parseLong(libraryName.substring(indexOfSeparator + 1));
            } catch (NumberFormatException ex) {
                // ignore
            }
            libraryName = libraryName.substring(0, indexOfSeparator);
            System.load(libraryFile.getCanonicalPath());
            JNIHelper.setManuallyLoadedLibrary(libraryName, libraryVersion);
        }
    } finally {
        IOUtils.closeQuietly(loadOrderStream);
    }
}

From source file:org.datavyu.util.NativeLoader.java

private static File copyFileToTmp(final String destName, final URL u) throws Exception {
    System.err.println("Attempting to load: " + u.toString());

    InputStream in = u.openStream();
    File outfile = new File(System.getProperty("java.io.tmpdir"), destName);

    // Create a temporary output location for the library.
    FileOutputStream out = new FileOutputStream(outfile);
    BufferedOutputStream dest = new BufferedOutputStream(out, BUFFER);

    int count;/*from w w w.j a  v a 2s.  com*/
    byte[] data = new byte[BUFFER];
    while ((count = in.read(data, 0, BUFFER)) != -1) {
        dest.write(data, 0, count);
    }

    dest.flush();
    dest.close();
    out.close();
    in.close();

    loadedLibs.add(outfile);
    System.err.println("Temp File:" + outfile);
    System.load(outfile.toString());
    System.err.println("Extracted lib: " + outfile);
    return outfile;
}