Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.firebirdsql.gds.impl.jni;
public class DynamicLibraryLoader {
    private static final String TEMP_SUFFIX = "jlib";
    private static final String TEMP_PREFIX = "jaybird";
Load the library from the classpath. This method will check whether the classpath contains the specified library. If no library can be found, false is returned. However, when classpath contains the requested library, its content is copied into the temporary file and this file is later loaded using the java.lang.Runtime.load(java.lang.String) method.

libraryName name of the library to load. This name is translated into the platform-depended name using the java.lang.System.mapLibraryName(java.lang.String) method. The new name is used to search the library in the path.
true if library was found in the classpath and was successfully loaded into the JVM.
Throws: If I/O error occured during the operation.
    public static boolean loadLibraryFromClassPath(String libraryNamethrows IOException {
        String platformLibName = System.mapLibraryName(libraryName);
        InputStream in = DynamicLibraryLoader.class.getResourceAsStream(platformLibName);
        if (in == null)
            return false;
        try {
            File tempFile = File.createTempFile();
            FileOutputStream out = new FileOutputStream(tempFile);
            int counter = 0;
            byte[] buffer = new byte[8192];
            while((counter = != -1)
                out.write(buffer, 0, counter);
            String canonicalFileName = tempFile.getCanonicalPath();
            return true;
        } finally {
New to GrepCode? Check out our FAQ X