Methods Summary |
---|
public java.io.File | computeDirectoryForClass(java.lang.Class classInJar)Computes the directory where NativeLibraryFinder will search for
a native library. If classInJar is a class in a jar
file then it will return the dirctory that contains the jar file.
This is a common installation setup where foo.jar and foo.dll are
installed into the same directory. If the jar file was downloaded
via http then this method will return null .
If classInJar is a class that was not contained in a
jar file, then this will return the directory that is the root of
the class tree. This is the same location as a resource with the
path of "/" would return. This is useful if the native library
will eventually be packaged as a resource in a jar file, because
finding the library directory here will allow the code to skip extracting
the native library.
String strDir = computeDirectoryStringForClass(classInJar);
if (strDir == null) {
return null;
}
return new File(strDir);
|
java.lang.String | computeDirectoryForFileUrl(java.net.URL url)
String strUrl = url.toExternalForm();
String classesDirectory = strUrl.substring("file:".length(), strUrl.length() - m_classAsResourcePath.length());
File dir = new File(classesDirectory);
return dir.getAbsolutePath();
|
java.lang.String | computeDirectoryForJarUrl(java.net.URL url)
File jarFile = computeJarFile(url);
return jarFile.getParent();
|
private java.lang.String | computeDirectoryStringForClass(java.lang.Class classInJar)
m_classAsResourcePath = computeResourceToFind(classInJar);
URL url = classInJar.getResource(m_classAsResourcePath);
String directory = null;
if ("file".equals(url.getProtocol())) {
directory = computeDirectoryForFileUrl(url);
}
if ("jar".equals(url.getProtocol())) {
directory = computeDirectoryForJarUrl(url);
}
return directory;
|
protected java.io.File | computeJarFile(java.net.URL url)
String strUrl = url.toExternalForm();
String jarPath = strUrl.substring("jar:file:".length(), strUrl.length() - m_classAsResourcePath.length() - "!".length());
File jarFile = new File(jarPath);
return jarFile;
|
java.io.File | computePath(java.lang.String directory, java.lang.String osPrefix, java.lang.String mappedName)
return new File(directory, osPrefix + mappedName);
|
private java.lang.String | computeResourceToFind(java.lang.Class classInJar)
String pathToClass = classInJar.getName().replace('.", '/");
String resourceToFind = "/" + pathToClass + ".class";
return resourceToFind;
|
public void | findAndLoad(java.lang.Class classInJar, java.lang.String libraryName)
String directory = computeDirectoryStringForClass(classInJar);
if (directory != null) {
tryOsPrefixes(directory, templateGetMappedName(classInJar, libraryName));
}
|
public java.lang.String | getClassAsResourcePath()
return m_classAsResourcePath;
|
public void | setClassAsResourcePath(java.lang.String resourceToFind)
m_classAsResourcePath = resourceToFind;
|
protected java.lang.String | templateGetMappedName(java.lang.Class classInJar, java.lang.String libraryName)Override to change the mapped name this class uses to search for
the native library.
return System.mapLibraryName(libraryName);
|
void | tryOsPrefixes(java.lang.String directory, java.lang.String mappedName)
for (int i = 0; i < NativeLibraryFinder.OS_PREFIXES.length; i++) {
String osPrefix = NativeLibraryFinder.OS_PREFIXES[i];
File fullPath = computePath(directory, osPrefix, mappedName);
s_logger.log(Level.FINE, "trying {0}", fullPath);
if (fullPath.exists()) {
System.load(fullPath.getAbsolutePath());
return;
}
}
throw new UnsatisfiedLinkError("No library found");
|