/* * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.glass.utils; import java.io.File; import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashSet; public class NativeLibLoader { private static final HashSet loaded = new HashSet(); public static synchronized void loadLibrary(String libname) { if (!loaded.contains(libname)) { loadLibraryInternal(libname); loaded.add(libname); } } private static boolean verbose = false; private static File libDir = null; private static String libPrefix = ""; private static String libSuffix = ""; static { AccessController.doPrivileged((PrivilegedAction) () -> { verbose = Boolean.getBoolean("javafx.verbose"); return null; }); } private static String[] initializePath(String propname) { String ldpath = System.getProperty(propname, ""); String ps = File.pathSeparator; int ldlen = ldpath.length(); int i, j, n; // Count the separators in the path i = ldpath.indexOf(ps); n = 0; while (i >= 0) { n++; i = ldpath.indexOf(ps, i + 1); } // allocate the array of paths - n :'s = n + 1 path elements String[] paths = new String[n + 1]; // Fill the array with paths from the ldpath n = i = 0; j = ldpath.indexOf(ps); while (j >= 0) { if (j - i > 0) { paths[n++] = ldpath.substring(i, j); } else if (j - i == 0) { paths[n++] = "."; } i = j + 1; j = ldpath.indexOf(ps, i); } paths[n] = ldpath.substring(i, ldlen); return paths; } private static void loadLibraryInternal(String libraryName) { // Look for the library in the same directory as the jar file // containing this class. // If that fails, then try System.loadLibrary as a last resort. try { loadLibraryFullPath(libraryName); } catch (UnsatisfiedLinkError ex) { // NOTE: First attempt to load the libraries from the java.library.path. // This allows FX to find more recent versions of the shared libraries // from java.library.path instead of ones that might be part of the JRE // String [] libPath = initializePath("java.library.path"); for (int i=0; i