List of usage examples for java.lang System load
@CallerSensitive public static void load(String filename)
From source file:com.hadoop.compression.fourmc.FourMcNativeCodeLoader.java
private static synchronized void loadLibrary() { if (nativeLibraryLoaded) { LOG.info("hadoop-4mc: native library is already loaded"); return;/*from w ww. j a v a 2s . c om*/ } if (useBinariesOnLibPath()) { try { System.loadLibrary("hadoop-4mc"); nativeLibraryLoaded = true; LOG.info("hadoop-4mc: loaded native library (lib-path)"); } catch (Exception e) { LOG.error("hadoop-4mc: cannot load native library (lib-path): ", e); } return; } // unpack and use embedded libraries String resourceName = resourceName(); InputStream is = FourMcNativeCodeLoader.class.getResourceAsStream(resourceName); if (is == null) { throw new UnsupportedOperationException( "Unsupported OS/arch, cannot find " + resourceName + ". Please try building from source."); } File tempLib; try { tempLib = File.createTempFile("libhadoop-4mc", "." + os().libExtension); // copy to tempLib FileOutputStream out = new FileOutputStream(tempLib); try { byte[] buf = new byte[4096]; while (true) { int read = is.read(buf); if (read == -1) { break; } out.write(buf, 0, read); } try { out.close(); out = null; } catch (IOException e) { // ignore } System.load(tempLib.getAbsolutePath()); nativeLibraryLoaded = true; LOG.info("hadoop-4mc: loaded native library (embedded)"); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { // ignore } if (tempLib.exists()) { if (!nativeLibraryLoaded) { tempLib.delete(); } else { tempLib.deleteOnExit(); } } } } catch (Exception e) { LOG.error("hadoop-4mc: cannot load native library (embedded): ", e); } }
From source file:org.tigris.subversion.svnclientadapter.javahl.JhlClientAdapterFactory.java
@SuppressWarnings("rawtypes") public static boolean isAvailable() { if (!availabilityCached) { Class c = null;//from w w w .ja va 2 s .com try { // load a JavaHL class to see if it is found. Do not use SVNClient as // it will try to load native libraries and we do not want that yet c = Class.forName("org.apache.subversion.javahl.ClientException"); if (c == null) return false; } catch (Throwable t) { availabilityCached = true; return false; } // if library is already loaded, it will not be reloaded //workaround to solve Subclipse ISSUE #83 // we will ignore these exceptions to handle scenarios where // javaHL was built diffently. Ultimately, if javaHL fails to load // because of a problem in one of these libraries the proper behavior // will still occur -- meaning JavaHL adapter is disabled. if (isOsWindows()) { for (int i = 0; i < WINDOWSLIBS.length; i++) { try { System.loadLibrary(WINDOWSLIBS[i]); } catch (Exception e) { javaHLErrors.append(e.getMessage()).append("\n"); } catch (UnsatisfiedLinkError e) { javaHLErrors.append(e.getMessage()).append("\n"); } } } //workaround to solve Subclipse ISSUE #83 available = false; try { /* * see if the user has specified the fully qualified path to the native * library */ try { String specifiedLibraryName = System.getProperty("subversion.native.library"); if (specifiedLibraryName != null) { System.load(specifiedLibraryName); available = true; } } catch (UnsatisfiedLinkError ex) { javaHLErrors.append(ex.getMessage()).append("\n"); } if (!available) { /* * first try to load the library by the new name. * if that fails, try to load the library by the old name. */ try { System.loadLibrary("libsvnjavahl-1"); } catch (UnsatisfiedLinkError ex) { javaHLErrors.append(ex.getMessage() + "\n"); try { System.loadLibrary("svnjavahl-1"); } catch (UnsatisfiedLinkError e) { javaHLErrors.append(e.getMessage()).append("\n"); System.loadLibrary("svnjavahl"); } } available = true; } } catch (Exception e) { available = false; javaHLErrors.append(e.getMessage()).append("\n"); } catch (UnsatisfiedLinkError e) { available = false; javaHLErrors.append(e.getMessage()).append("\n"); } finally { availabilityCached = true; } if (!available) { String libraryPath = System.getProperty("java.library.path"); if (libraryPath != null) javaHLErrors.append("java.library.path = " + libraryPath); // System.out.println(javaHLErrors.toString()); } else { // At this point, the library appears to be available, but // it could be too old version of JavaHL library. We have to try // to get the version of the library to be sure. try { ISVNClient svnClient = new SVNClient(); Version version = svnClient.getVersion(); if (version.getMajor() == 1 && version.getMinor() == 8) available = true; else { available = false; javaHLErrors = new StringBuffer( "Incompatible JavaHL library loaded. Subversion 1.8.x required."); } } catch (UnsatisfiedLinkError e) { available = false; javaHLErrors = new StringBuffer( "Incompatible JavaHL library loaded. 1.8.x or later required."); } } } return available; }
From source file:org.nd4j.linalg.api.buffer.util.LibUtils.java
/** * Load the library with the given name from a resource. * The extension for the current OS will be appended. * * @param libName The library name/* w w w .ja v a2s . c om*/ * @throws Throwable If the library could not be loaded */ public static void loadTempBinaryFile(String libName) throws Exception { String libPrefix = createLibPrefix(); String libExtension = createLibExtension(); String fullName = libPrefix + libName; String resourceName = fullName + "." + libExtension; ClassPathResource resource = new ClassPathResource(resourceName); InputStream inputStream = resource.getInputStream(); if (inputStream == null) { throw new NullPointerException("No resource found with name '" + resourceName + "'"); } File tempFile = new File(System.getProperty("java.io.tmpdir"), fullName + "." + libExtension); tempFile.deleteOnExit(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempFile)); IOUtils.copy(inputStream, bos); bos.flush(); inputStream.close(); bos.close(); System.load(tempFile.getAbsolutePath()); }
From source file:org.apache.reef.javabridge.LibLoader.java
/** * load assembly//from w w w . j av a2 s.c o m * @param fileOut * @param managed */ private void loadAssembly(final File fileOut, final boolean managed) { if (managed) { NativeInterop.loadClrAssembly(fileOut.toString()); LOG.log(Level.INFO, "Loading DLL managed done"); } else { System.load(fileOut.toString()); LOG.log(Level.INFO, "Loading DLL not managed done"); } }
From source file:org.nd4j.linalg.api.buffer.util.LibUtils.java
/** * Load the library with the given name from a resource. * The extension for the current OS will be appended. * * @param libName The library name//from w w w . j ava2 s . c om * @throws Throwable If the library could not be loaded */ public static void loadJavaCppResource(String libName) throws Throwable { String libPrefix = createLibPrefix(); String libExtension = createLibExtension(); String fullName = libPrefix + libName; String resourceName = fullName + "." + libExtension; ClassPathResource resource = new ClassPathResource(resourceName); InputStream inputStream = resource.getInputStream(); if (inputStream == null) { throw new NullPointerException("No resource found with name '" + resourceName + "'"); } File tempFile = File.createTempFile(fullName, "." + libExtension); tempFile.deleteOnExit(); OutputStream outputStream = null; try { outputStream = new FileOutputStream(tempFile); byte[] buffer = new byte[8192]; while (true) { int read = inputStream.read(buffer); if (read < 0) { break; } outputStream.write(buffer, 0, read); } outputStream.flush(); outputStream.close(); outputStream = null; System.load(tempFile.toString()); } finally { if (outputStream != null) { outputStream.close(); } } }
From source file:pt.lsts.neptus.plugins.europa.EuropaUtils.java
public static String loadLibrary(String lib) throws Exception { // Loook for it String library = locateLibrary(lib); NeptusLog.pub().info("native library loaded from " + library + "."); // load the library directly System.load(library); return library; }
From source file:com.microsoft.applicationinsights.internal.perfcounter.JniPCConnector.java
/** * The method will try to extract the dll for the Windows performance counters to a local * folder and then will try to load it. The method will do all that by doing the following things: * 1. Find the OS type (64/32) currently supports only 64 bit. * 2. Will find the path to extract to, which is %temp%/AI_BASE_FOLDER/AI_NATIVE_FOLDER/sdk_version_number * 3. Find out whether or not the file already exists in that directory * 4. If the dll is not there, the method will extract it from the jar to that directory * 5. The method will call System.load to load the dll and by doing so we are ready to use it * @return true on success, otherwise false * @throws IOException If there are errors in opening/writing/reading/closing etc. * Note that the method might throw RuntimeExceptions due to critical issues *///from w ww . j a v a 2 s .c o m private static void loadNativeLibrary() throws IOException { String model = System.getProperty("sun.arch.data.model"); String libraryToLoad = BITS_MODEL_64.equals(model) ? NATIVE_LIBRARY_64 : NATIVE_LIBRARY_32; File dllPath = buildDllLocalPath(); File dllOnDisk = new File(dllPath, libraryToLoad); if (!dllOnDisk.exists()) { extractToLocalFolder(dllOnDisk, libraryToLoad); } System.load(dllOnDisk.toString()); initNativeCode(); InternalLogger.INSTANCE.trace("Successfully loaded library '%s'", libraryToLoad); }
From source file:net.tomp2p.simgrid.SimGridTomP2P.java
private static void loadLib(String name) throws IOException { String pathJar = null;/* w w w .j av a2s .c om*/ String pathEclipse = null; if (OSTester.is64bit() && OSTester.isUnix()) { name = "lib" + name + ".so"; //jar version pathJar = "libs" + File.separator + "x64" + File.separator + name; //eclipse workspace version pathEclipse = File.separator + "libs" + File.separator + "x64" + File.separator + name; } if (pathJar == null || pathEclipse == null) { throw new IOException("Platform not supported"); } InputStream in = SimGridTomP2P.class.getResourceAsStream(pathJar); if (in == null) { in = SimGridTomP2P.class.getResourceAsStream(pathEclipse); } File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + name); fileOut.deleteOnExit(); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString()); }
From source file:com.aps490.drdc.prototype.MainActivity.java
public static void initNativeLib(Context context) { try {/*from ww w. j ava 2 s .c o m*/ // Try loading our native lib, see if it works... System.loadLibrary("libarchitect"); } catch (UnsatisfiedLinkError er) { ApplicationInfo appInfo = context.getApplicationInfo(); String libName = "libarchitect.so"; String destPath = context.getFilesDir().toString(); try { String soName = destPath + File.separator + libName; new File(soName).delete(); UnzipUtil.extractFile(appInfo.sourceDir, "lib/" + Build.CPU_ABI + "/" + libName, destPath); System.load(soName); } catch (IOException e) { // extractFile to app files dir did not work. Not enough space? Try elsewhere... destPath = context.getExternalCacheDir().toString(); // Note: location on external memory is not secure, everyone can read/write it... // However we extract from a "secure" place (our apk) and instantly load it, // on each start of the app, this should make it safer. String soName = destPath + File.separator + libName; new File(soName).delete(); // this copy could be old, or altered by an attack try { UnzipUtil.extractFile(appInfo.sourceDir, "lib/" + Build.CPU_ABI + "/" + libName, destPath); System.load(soName); } catch (IOException e2) { Log.e("AMMAR:", "Exception in InstallInfo.init(): " + e); e.printStackTrace(); } } } }
From source file:org.linphone.tools.OpenH264DownloadHelper.java
/** * Try to download and load codec//from w w w .jav a 2 s.c o m * Requirements : * fileDirection * nameFileDownload * urlDownload * nameLib * codecDownListener */ public void downloadCodec() { Thread thread = new Thread(new Runnable() { @Override public void run() { try { String path = fileDirection + "/" + nameLib; URL url = new URL(urlDownload); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.connect(); Log.i("OpenH264Downloader", " "); InputStream inputStream = urlConnection.getInputStream(); FileOutputStream fileOutputStream = new FileOutputStream( fileDirection + "/" + nameFileDownload); int totalSize = urlConnection.getContentLength(); openH264DownloadHelperListener.OnProgress(0, totalSize); Log.i("OpenH264Downloader", " Download file:" + nameFileDownload); byte[] buffer = new byte[4096]; int bufferLength; int total = 0; while ((bufferLength = inputStream.read(buffer)) > 0) { total += bufferLength; fileOutputStream.write(buffer, 0, bufferLength); openH264DownloadHelperListener.OnProgress(total, totalSize); } fileOutputStream.close(); inputStream.close(); Log.i("OpenH264Downloader", " Uncompress file:" + nameFileDownload); FileInputStream in = new FileInputStream(fileDirection + "/" + nameFileDownload); FileOutputStream out = new FileOutputStream(path); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); while ((bufferLength = bzIn.read(buffer)) > 0) { out.write(buffer, 0, bufferLength); } in.close(); out.close(); bzIn.close(); Log.i("OpenH264Downloader", " Remove file:" + nameFileDownload); new File(fileDirection + "/" + nameFileDownload).delete(); Log.i("OpenH264Downloader", " Loading plugin:" + path); System.load(path); openH264DownloadHelperListener.OnProgress(2, 1); } catch (FileNotFoundException e) { openH264DownloadHelperListener.OnError(e.getLocalizedMessage()); } catch (IOException e) { openH264DownloadHelperListener.OnError(e.getLocalizedMessage()); } } }); thread.start(); }