aboutsummaryrefslogtreecommitdiff
path: root/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala
diff options
context:
space:
mode:
Diffstat (limited to 'jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala')
-rw-r--r--jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala b/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala
index 46d4b2d..261e52b 100644
--- a/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala
+++ b/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala
@@ -1,11 +1,10 @@
package ch.jodersky.jni
import java.io.{File, FileOutputStream, InputStream, OutputStream}
-import scala.io.Source
/**
- * Provides enhanced native library loading functionality.
- */
+ * Provides enhanced native library loading functionality.
+ */
object NativeLoader {
/** Name of the shared library file that is contained in a jar. */
@@ -13,7 +12,7 @@ object NativeLoader {
final val BufferSize = 4096
- /** Extract a resource from this class loader to a temporary file. */
+ /** Extracts a resource from this class loader to a temporary file. */
private def extract(path: String): Option[File] = {
var in: Option[InputStream] = None
var out: Option[OutputStream] = None
@@ -45,12 +44,16 @@ object NativeLoader {
msg
)
+ /**
+ * Gets the absolute, full path of a resource on the classpath, given a libraryPath
+ * and platform.
+ */
def fullLibraryPath(libraryPath: String, platform: Platform) = {
- libraryPath + "/native/" + platform.id + "/" + LibraryName
+ libraryPath + "/native/" + platform.id + "/" + LibraryName
}
private def loadFromJar(libraryPath: String): Unit = {
- val platform = Platform.current.getOrElse{
+ val platform = Platform.current.getOrElse {
loadError("Cannot determine current platform.")
}
@@ -63,10 +66,10 @@ object NativeLoader {
}
/**
- * Load a native library from the available library path or fall back
+ * Loads a native library from the available library path or fall back
* to extracting and loading a native library from available resources.
*/
- def load(library: String, libraryPath: String): Unit = try {
+ def load(libraryPath: String, library: String): Unit = try {
System.loadLibrary(library)
} catch {
case ex: UnsatisfiedLinkError => loadFromJar(libraryPath)