/** * 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 { boolean tmpIsPure = false; if (Boolean.getBoolean(PURE_MODE_PROPERTY)) { if (debug) { System.out.println("property " + PURE_MODE_PROPERTY + " is true"); } tmpIsPure = true; } else { tmpIsPure = false; try { // Attempting to load the library SharedLibrary.loadLibrary(debug); } catch (UnsatisfiedLinkError ignore) { if (debug) { System.out.println( "java.library.path is set to:\n" + System.getProperty("java.library.path")); System.out.println("Error: Failed to load library " + SharedLibrary.getName()); ignore.printStackTrace(); } tmpIsPure = true; } } isPure = tmpIsPure; is64Bit = SharedLibrary.is64Bit(); String osName = System.getProperty("os.name", "unknown"); osStatsAreAvailable = osName.startsWith("Linux") || !isPure; }
/** * Look up the given global variable within this library. * * @param symbolName * @return Pointer representing the global variable address * @throws UnsatisfiedLinkError if the symbol is not found */ public Pointer getGlobalVariableAddress(String symbolName) { try { return new Pointer(getSymbolAddress(symbolName)); } catch (UnsatisfiedLinkError e) { throw new UnsatisfiedLinkError("Error looking up '" + symbolName + "': " + e.getMessage()); } }
static { try { System.loadLibrary("effectfisheye"); } catch (UnsatisfiedLinkError unsatisfiedlinkerror) { unsatisfiedlinkerror.printStackTrace(); } }
public void initSystem() { Pointer[] p = new Pointer[1]; try { int result = LibUsbLibrary.libUsb.libusb_init(p); checkError("init", result); this.context = p[0]; // LibUsbLibrary.libUsb.libusb_set_debug(this.context, 4); } catch (UnsatisfiedLinkError e) { if (e.getMessage().matches(".*cannot open shared object file.*")) { System.out.println("Libusb not found. Minimum libusb version is 1.0.14"); System.out.println("It can be downloaded on http://www.libusbx.org"); } else { System.out.println(e.getLocalizedMessage()); } System.exit(1); } try { libusb_version v = LibUsbLibrary.libUsb.libusb_get_version(); if (v.major != (short) 1 || v.minor != (short) 0 || v.micro < (short) 14) { System.out.println( "Minimum libusb version is 1.0.14. Found " + v.major + "." + v.minor + "." + v.micro); System.out.println("It can be downloaded on http://www.libusbx.org"); System.exit(1); } } catch (UnsatisfiedLinkError e) { System.out.println( "A libusb was found but not with the right version. Minimum libusb version is 1.0.14"); System.out.println("It can be downloaded on http://www.libusbx.org"); System.exit(1); } }
/** * Creates a new JNI communication handler for the Control & Monitoring API. * * @throws CMException Thrown when the C JNI library cannot be loaded (libcmjni) or one of the XML * (de)serializers cannot be initialised. */ public JniCommunicator() throws CommunicationException { try { System.loadLibrary("cmjni"); } catch (UnsatisfiedLinkError e) { System.err.println("Could not load JNI library 'cmjni'. Reason:\n" + e.getMessage()); throw new CommunicationException("Could not load JNI library 'cmjni': " + e.getMessage()); } initialized = false; JniCommunicator.connectionAlive = false; entityDeserializer = DataTransformerFactory.getEntityDeserializer(DataTransformerFactory.XML); typeDeserializer = DataTransformerFactory.getMetaTypeDeserializer(DataTransformerFactory.XML); entitySerializer = DataTransformerFactory.getEntitySerializer(DataTransformerFactory.XML); statusDeserializer = DataTransformerFactory.getStatusDeserializer(DataTransformerFactory.XML); snapshotDeserializer = DataTransformerFactory.getSnapshotDeserializer(DataTransformerFactory.XML); snapshotSerializer = DataTransformerFactory.getSnapshotSerializer(DataTransformerFactory.XML); untypedSampleDeserializer = DataTransformerFactory.getUntypedSampleDeserializer(DataTransformerFactory.XML); userDataSerializer = DataTransformerFactory.getUserDataSerializer(DataTransformerFactory.XML); qosDeserializer = DataTransformerFactory.getQoSDeserializer(DataTransformerFactory.XML); qosSerializer = DataTransformerFactory.getQoSSerializer(DataTransformerFactory.XML); statisticsDeserializer = DataTransformerFactory.getStatisticsDeserializer(DataTransformerFactory.XML); }
@Override public void getElements(Vector<CefPostDataElement> elements) { try { N_GetElements(elements); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } }
static { try { System.loadLibrary("ADPCMAndroid"); // return; } catch (UnsatisfiedLinkError localUnsatisfiedLinkError) { System.out.println("loadLibrary(ADPCMAndroid)," + localUnsatisfiedLinkError.getMessage()); } }
// Load the native library static { try { System.loadLibrary("LibSVMTest"); status = modelInitialize("/Users/roygao/Downloads/libsvm1.model"); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } }
@Override public void removeElements() { try { N_RemoveElements(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } }
static { try { System.loadLibrary("qfs_access"); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); System.err.println("Unable to load qfs_access native library"); System.exit(1); } }
@Override public boolean addElement(CefPostDataElement element) { try { return N_AddElement(element); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } return false; }
@Override public int getElementCount() { try { return N_GetElementCount(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } return 0; }
@Override public boolean isReadOnly() { try { return N_IsReadOnly(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } return false; }
static { try { System.loadLibrary("OpenCVEngine"); System.loadLibrary("OpenCVEngine_jni"); mIsReady = true; } catch (UnsatisfiedLinkError e) { mIsReady = false; e.printStackTrace(); } }
@Override protected void finalize() throws Throwable { try { N_CefPostData_DTOR(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } finally { super.finalize(); } }
public static final CefPostData createNative() { CefPostData_N result = new CefPostData_N(); try { result.N_CefPostData_CTOR(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } if (result.N_CefHandle == 0) return null; return result; }
static { try { System.loadLibrary("kfs_access"); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); System.err.println( "Unable to load kfs_access native library: " + System.getProperty("java.library.path")); System.exit(1); } }
/** * Attempt to make errors generated when 3D not available a little nicer. {@inheritDoc} * * @see java.awt.Component#addNotify() */ @Override public void addNotify() { try { super.addNotify(); } catch (UnsatisfiedLinkError ex) { LogContext.getLogger() .warning("Sorry, 3D model rendering has not been enabled " + "for this platform."); ex.printStackTrace(); } }
/* (non-Javadoc) * @see jhorn.solver.ProverFactory#spawn() */ @Override public Prover spawn() { Prover z3 = null; try { z3 = new Z3Prover(); // z3 = new Z3HornProver(); } catch (UnsatisfiedLinkError e) { Log.error("Cannot start z3. " + e.toString()); } return z3; }
/** Start the search with the loaded terms. */ public void doSearch() { try { /* Start timing */ timer.start(); /* Start a new desktop query */ JGDQuery jgdQuery = new JGDQuery(query); /* Limit the number of results */ jgdQuery.setNum(maxResults); /* Filter by files only */ jgdQuery.setFilterByFiles(); /* Execute the jgdQuery */ Results jgdResults = jgdQuery.execute(); /* Get the result */ List<?> l = jgdResults.getResult(); for (Object jdgResult : l) { GoogleDesktopFile googleDesktopFile = (GoogleDesktopFile) jdgResult; /* Create a new file object from the result */ File file = new File(googleDesktopFile.get_uri()); /* If this fails, skip it */ if (file == null) { continue; } log.info("Local result found: " + file.toString()); Resource resource = new Resource(); resource.setArticle(new FileArticle()); resource.setData(new FileData(file)); /* Add to total results with extended data */ results.put(file.toURI(), resource); } } catch (Exception e) { log.error(e.getMessage(), e); } catch (UnsatisfiedLinkError ule) { log.error(ule.getMessage(), ule); } catch (NoClassDefFoundError ncdefe) { log.error(ncdefe.getMessage(), ncdefe); } /* Stop timing */ timer.stop(); }
public void testIncludeSymbolNameInLookupError() { NativeLibrary lib = NativeLibrary.getInstance("testlib"); try { lib.getGlobalVariableAddress(getName()); fail("Non-existent global variable lookup should fail"); } catch (UnsatisfiedLinkError e) { assertTrue( "Expect symbol name in error message: " + e.getMessage(), e.getMessage().indexOf(getName()) != -1); } }
public SigarLibrary() { logger.info("Initializing SIGAR library"); try { sigar = new Sigar(); mounts = sigar.getFileSystemMap(); initialized = true; } catch (SigarException e) { logger.info("Could not initialize SIGAR library {} ", e.getMessage()); } catch (UnsatisfiedLinkError linkError) { logger.info("Could not initialize SIGAR library {} ", linkError.getMessage()); } }
private static synchronized void loadNativeLibrary() { String fullname = System.mapLibraryName("hello"); String suffix = fullname.substring(fullname.lastIndexOf('.')); if (suffix.equalsIgnoreCase(".jnilib")) suffix = ".dylib"; String libname = "libxml2j" + suffix; File targetLibrary = null; File localXcodeLibrary = new File( "/Users/rath/Library/Developer/Xcode/DerivedData/libxml2-java-fkrlovtvxnmqhfhhoxmlslcqmtjx/Build/Products/Debug/" + libname); if (localXcodeLibrary.exists() && localXcodeLibrary.lastModified() + (1000L * 60L * 30L) > System.currentTimeMillis()) { targetLibrary = localXcodeLibrary; System.out.println("*****************************************"); System.out.println("* Using libxml2j.dylib built on Xcode 5 *"); System.out.println("*****************************************"); } File localLibrary = new File("src/main/c/" + libname); if (targetLibrary == null && localLibrary.exists()) { targetLibrary = localLibrary; } if (targetLibrary == null) { String bundleLibname = Utils.getPlatformDependentBundleName(); targetLibrary = new File(System.getProperty("java.io.tmpdir"), bundleLibname); try { Utils.copyAndClose(LibXml.class.getResourceAsStream("/" + bundleLibname), targetLibrary); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } try { System.load(targetLibrary.getAbsolutePath()); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); System.err.println("=============================================="); System.err.println(" We can't find libxml2 on your system "); System.err.println(" centos $ sudo yum install libxml2-devel "); System.err.println(" ubuntu $ sudo apt-get install libxml2-dev "); System.err.println(" macosx $ sudo port install libxml2 "); System.err.println("=============================================="); System.exit(1); } initInternalParser(); }
/** * Method to actual load the library and post process more meaningful error messages if necessary. * * @param name native library (not extensions or directory paths) * @param errors the errors * @return the library */ public static boolean loadLibrary(String name, List<Error> errors) { Error error = null; try { System.loadLibrary(name); } catch (UnsatisfiedLinkError e) { error = e; String msg = e.getMessage(); String mappedName = System.mapLibraryName(name); if (msg.contains("dependent libraries")) { error = new UnsatisfiedLinkError( mappedName + " native library is found, but needs " + " dependency library(ies) installed first."); } if (msg.contains("specified procedure")) { error = new UnsatisfiedLinkError( "Dependency version mismatch: " + mappedName + " library is found, but can't find a required native function" + " call it is dependent on. Make sure all dependencies at the" + " right version levels are installed."); } if (msg.contains("java.library.path")) { error = new UnsatisfiedLinkError( mappedName + " native library is not found. " + "Make sure its installed in /usr/lib or /usr/lib64 or " + "\\windows\\system32 or \\widows\\system64 or " + "set JVM -Djava.library.path=<dir_path_jnetpcap_library> to " + "its location."); } } catch (Error e) { error = e; } if (error != null) { errors.add(error); } return error == null; }
// Load video dll static { try { if (!ini) { System.loadLibrary("libs/dsj"); System.out.println("Video DLL loaded correctly"); // La siguiente linea comentada devuelve el número de bits del SO // System.out.println(System.getProperty("sun.arch.data.model")); ini = true; } } catch (UnsatisfiedLinkError e) { e.printStackTrace(); System.out.println("Video DLL not loaded"); } }
public static String load(String libname, String mode) { try { String lib = "retin_" + libname + "-" + getArchName() + "-" + getCCName() + "-" + mode; // System.out.println ("Library "+lib+" try..."); System.loadLibrary(lib); System.out.println("Library " + lib + " loaded"); } catch (Exception ex) { return ex.getMessage(); } catch (UnsatisfiedLinkError ex) { ex.printStackTrace(); return ex.getMessage(); } return null; }
static { try { System.loadLibrary("scilocalization"); } catch (SecurityException e) { System.err.println( "A security manager exists and does not allow the loading of the specified dynamic library."); System.err.println(e.getLocalizedMessage()); e.printStackTrace(System.err); } catch (UnsatisfiedLinkError e) { System.err.println("The native library scilocalization does not exist or cannot be found."); System.err.println(e.getLocalizedMessage()); e.printStackTrace(System.err); } }
/** * Create a new <code>Function</code> that is linked with a native function that follows the given * calling convention. * * <p>The allocated instance represents a pointer to the named native function from the supplied * library, called with the given calling convention. * * @param library {@link NativeLibrary} in which to find the function * @param functionName Name of the native function to be linked with * @param callFlags Function <a href="#callflags">call flags</a> * @param encoding Encoding for conversion between Java and native strings. * @throws UnsatisfiedLinkError if the given function name is not found within the library. */ Function(NativeLibrary library, String functionName, int callFlags, String encoding) { checkCallingConvention(callFlags & MASK_CC); if (functionName == null) throw new NullPointerException("Function name must not be null"); this.library = library; this.functionName = functionName; this.callFlags = callFlags; this.options = library.options; this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding(); try { this.peer = library.getSymbolAddress(functionName); } catch (UnsatisfiedLinkError e) { throw new UnsatisfiedLinkError( "Error looking up function '" + functionName + "': " + e.getMessage()); } }
public static Editline create(String appName) { Editline e = new Editline(); try { /** attempt to load libjava-editline.so */ System.loadLibrary("java-editline"); } catch (UnsatisfiedLinkError ule) { System.out.println("Error loading libjava-editline.so: " + ule.getMessage()); e._useEditline = false; } if (e._useEditline) { e.initEditlineImpl(appName); } return e; }