From f5fe5cfcf15e402e97182b58830c8f44d9877cae Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 22 Nov 2015 23:58:01 -0800 Subject: [PATCH] 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 --- .../edu/wpi/first/wpilibj/hal/JNIWrapper.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java index a07a5e1819..eb9154e455 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java @@ -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);