aboutsummaryrefslogtreecommitdiffstats
path: root/community/java-lz4/0003-prefer-system-lib.patch
blob: fd3720c7462967ee6f2def5ddc3e3980f671bc2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From 4727fc60f17a67b40c2bdf200a518a5d5708804c Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Thu, 7 Apr 2016 19:06:53 +0200
Subject: [PATCH] Try to load lz4-java from java.library.path, then fallback to bundled

Use system-provided lz4-java, if it's available on the java.library.path
(the default location where Java looks for native libraries), and fallback
to bundled binary if it's not. This allows user to use lz4 java even
on systems that are not directly supported, like Linux with musl libc,
uClibc etc.
---
 src/java/net/jpountz/util/Native.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/java/net/jpountz/util/Native.java b/src/java/net/jpountz/util/Native.java
index 1856841..e25708e 100644
--- a/src/java/net/jpountz/util/Native.java
+++ b/src/java/net/jpountz/util/Native.java
@@ -71,6 +71,16 @@ public static synchronized void load() {
     if (loaded) {
       return;
     }
+
+    // Try to load lz4-java (liblz4-java.so on Linux) from the java.library.path.
+    try {
+      System.loadLibrary("lz4-java");
+      loaded = true;
+      return;
+    } catch (UnsatisfiedLinkError ex) {
+      // Doesn't exist, so proceed to loading bundled library.
+    }
+
     String resourceName = resourceName();
     InputStream is = Native.class.getResourceAsStream(resourceName);
     if (is == null) {