JNIWrapper: Fall back to system library if not found in .jar.

This is useful primarily for debugging purposes (as the temporary file
written by the loader can't be easily loaded by gdb).

Change-Id: Ic4ea22ef88363c5ff998980b0352844645766fd9
This commit is contained in:
Peter Johnson
2015-11-22 23:58:01 -08:00
committed by Brad Miller (WPI)
parent 10e51f0261
commit f5fe5cfcf1

View File

@@ -14,34 +14,37 @@ public class JNIWrapper {
static {
try {
if (!libraryLoaded) {
// create temporary file
jniLibrary = File.createTempFile("libwpilibJavaJNI", ".so");
// flag for delete on exit
jniLibrary.deleteOnExit();
byte[] buffer = new byte[1024];
int readBytes;
InputStream is = JNIWrapper.class.getResourceAsStream("/linux-arm/libwpilibJavaJNI.so");
if (is != null) {
// create temporary file
jniLibrary = File.createTempFile("libwpilibJavaJNI", ".so");
// flag for delete on exit
jniLibrary.deleteOnExit();
OutputStream os = new FileOutputStream(jniLibrary);
byte[] buffer = new byte[1024];
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
int readBytes;
OutputStream os = new FileOutputStream(jniLibrary);
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
} finally {
os.close();
is.close();
}
} finally {
os.close();
is.close();
System.load(jniLibrary.getAbsolutePath());
} else {
System.loadLibrary("wpilibJavaJNI");
}
libraryLoaded = true;
}
System.load(jniLibrary.getAbsolutePath());
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);