diff --git a/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeBufferUtils.java b/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeBufferUtils.java index 089fb90..6a6284b 100644 --- a/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeBufferUtils.java +++ b/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeBufferUtils.java @@ -31,7 +31,6 @@ */ package com.jme3.alloc.util; -import java.io.IOException; import java.nio.Buffer; import java.nio.ByteBuffer; import com.jme3.alloc.util.loader.NativeBinaryLoader; @@ -44,7 +43,7 @@ public final class NativeBufferUtils { static { - loadNativeBinary(); + NativeBinaryLoader.loadLibraryIfEnabled(); } private NativeBufferUtils() { @@ -116,16 +115,4 @@ private NativeBufferUtils() { * @return a 32-bit or 64-bit integer (depending on the architecture) representing the memory address of the specified buffer */ public static native long getMemoryAdress(final ByteBuffer buffer); - - private static void loadNativeBinary() { - if (!NativeBinaryLoader.isAutoLoad()) { - return; - } - try { - /* extracts and loads the system specific library */ - NativeBinaryLoader.loadLibrary(); - } catch (IOException e) { - e.printStackTrace(); - } - } } \ No newline at end of file diff --git a/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeErrno.java b/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeErrno.java index 4f9c1aa..9924a3f 100644 --- a/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeErrno.java +++ b/jme3-alloc/src/main/java/com/jme3/alloc/util/NativeErrno.java @@ -31,7 +31,6 @@ */ package com.jme3.alloc.util; -import java.io.IOException; import com.jme3.alloc.util.loader.NativeBinaryLoader; /** @@ -42,12 +41,7 @@ public final class NativeErrno { static { - try { - /* extracts and loads the system specific library if it's not been loaded before */ - NativeBinaryLoader.loadLibrary(); - } catch (IOException e) { - e.printStackTrace(); - } + NativeBinaryLoader.loadLibraryIfEnabled(); } private NativeErrno() { diff --git a/jme3-alloc/src/main/java/com/jme3/alloc/util/loader/NativeBinaryLoader.java b/jme3-alloc/src/main/java/com/jme3/alloc/util/loader/NativeBinaryLoader.java index 0afea40..5642e5b 100644 --- a/jme3-alloc/src/main/java/com/jme3/alloc/util/loader/NativeBinaryLoader.java +++ b/jme3-alloc/src/main/java/com/jme3/alloc/util/loader/NativeBinaryLoader.java @@ -36,8 +36,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; import java.lang.UnsatisfiedLinkError; import com.jme3.alloc.util.NativeBufferUtils; +import com.jme3.alloc.util.NativeErrno; /** * Helper utility for loading native binaries. @@ -46,6 +49,7 @@ */ public final class NativeBinaryLoader { + private static final Logger LOGGER = Logger.getLogger(NativeBinaryLoader.class.getName()); private static final ReentrantLock LOCK = new ReentrantLock(); private static final int EOF = -1; private static boolean autoLoad = true; @@ -53,6 +57,23 @@ public final class NativeBinaryLoader { private NativeBinaryLoader() { } + /** + * Extracts and loads the variant specific binary from the output jar, handling the error messages, + * guarded by the {@link NativeBinaryLoader#isAutoLoad()}. + */ + public static void loadLibraryIfEnabled() { + if (!NativeBinaryLoader.isAutoLoad()) { + LOGGER.log(Level.WARNING, "Stock Jme3-alloc-NativeBinaryLoader is not enabled!"); + return; + } + try { + /* extracts and loads the system specific library */ + NativeBinaryLoader.loadLibrary(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Binary Not Found!", e); + } + } + /** * Extracts and loads the system and the architecture specific library from the output jar to the [user.dir]. * @@ -75,7 +96,7 @@ public static void loadLibrary() throws IOException { * Default value is [true]. * * @param isAutoLoad true to auto-extract and load the native binary dynamically, false otherwise. - * @see NativeBufferUtils#loadNativeBinary() + * @see NativeBinaryLoader#loadLibraryIfEnabled() */ public static void setAutoLoad(boolean isAutoLoad) { NativeBinaryLoader.autoLoad = isAutoLoad; @@ -83,10 +104,11 @@ public static void setAutoLoad(boolean isAutoLoad) { /** * Tests whether the native-binary will be auto-extracted and loaded when the - * class initializer of {@link NativeBufferUtils} is called. Default value is [true]. + * class initializer of {@link NativeBufferUtils} or {@link NativeErrno} is called. + * Default value is [true]. * * @return true if the native-binary is to be auto-extracted and loaded dynamically, false otherwise. - * @see NativeBufferUtils#loadNativeBinary() + * @see NativeBinaryLoader#loadLibraryIfEnabled() */ public static boolean isAutoLoad() { return autoLoad;