Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/java/net/jpountz/util/Native.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/java/net/jpountz/util/Native.java

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.FilenameFilter;
import java.security.AccessController;
import java.security.PrivilegedAction;

/** FOR INTERNAL USE ONLY */
public enum Native {
Expand Down Expand Up @@ -95,6 +97,24 @@ public boolean accept(File dir, String name) {
}
}

private static void loadLibrary(final String libName) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary(libName);
return null;
}
});
}

private static void loadLibraryFile(final String libFileName) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.load(libFileName);
return null;
}
});
}

public static synchronized void load() {
if (loaded) {
return;
Expand All @@ -104,7 +124,7 @@ public static synchronized void load() {

// Try to load lz4-java (liblz4-java.so on Linux) from the java.library.path.
try {
System.loadLibrary("lz4-java");
loadLibrary("lz4-java");
loaded = true;
return;
} catch (UnsatisfiedLinkError ex) {
Expand Down Expand Up @@ -134,7 +154,7 @@ public static synchronized void load() {
out.write(buf, 0, read);
}
}
System.load(tempLib.getAbsolutePath());
loadLibraryFile(tempLib.getAbsolutePath());
loaded = true;
} catch (IOException e) {
throw new ExceptionInInitializerError("Cannot unpack liblz4-java: " + e);
Expand Down