Skip to content

Commit 29753d9

Browse files
committed
Update issue 26
Applied the patch from tucu; load org-xerial-snappy.properties file when it can be found from the context class loader.
1 parent 57190cd commit 29753d9

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/main/java/org/xerial/snappy/SnappyLoader.java

+46-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.security.NoSuchAlgorithmException;
4040
import java.security.ProtectionDomain;
4141
import java.util.ArrayList;
42+
import java.util.Enumeration;
4243
import java.util.List;
4344
import java.util.Properties;
4445

@@ -84,6 +85,7 @@
8485
*/
8586
public class SnappyLoader
8687
{
88+
public static final String SNAPPY_SYSTEM_PROPERTIES_FILE = "org-xerial-snappy.properties";
8789
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path";
8890
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name";
8991
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir";
@@ -93,6 +95,42 @@ public class SnappyLoader
9395
private static boolean isLoaded = false;
9496
private static SnappyNativeAPI api = null;
9597

98+
/**
99+
* load system properties when configuration file of the name
100+
* {@link #SNAPPY_SYSTEM_PROPERTIES_FILE} is found
101+
*/
102+
private static void loadSnappySystemProperties() {
103+
try {
104+
InputStream is = Thread.currentThread().getContextClassLoader()
105+
.getResourceAsStream(SNAPPY_SYSTEM_PROPERTIES_FILE);
106+
107+
if (is == null)
108+
return; // no configuration file is found
109+
110+
// Load property file
111+
Properties props = new Properties();
112+
props.load(is);
113+
is.close();
114+
Enumeration< ? > names = props.propertyNames();
115+
while (names.hasMoreElements()) {
116+
String name = (String) names.nextElement();
117+
if (name.startsWith("org.xerial.snappy.")) {
118+
if (System.getProperty(name) == null) {
119+
System.setProperty(name, props.getProperty(name));
120+
}
121+
}
122+
}
123+
}
124+
catch (Throwable ex) {
125+
System.err.println("Could not load '" + SNAPPY_SYSTEM_PROPERTIES_FILE + "' from classpath: "
126+
+ ex.toString());
127+
}
128+
}
129+
130+
static {
131+
loadSnappySystemProperties();
132+
}
133+
96134
private static ClassLoader getRootClassLoader() {
97135
ClassLoader cl = Thread.currentThread().getContextClassLoader();
98136
while (cl.getParent() != null) {
@@ -407,9 +445,16 @@ static File findNativeLibrary() {
407445
}
408446
}
409447

410-
return null; // Use a pre-installed snappyjava
448+
return null; // Use a pre-installed libsnappyjava
411449
}
412450

451+
/**
452+
* Get the snappy-java version by reading pom.properties embedded in jar.
453+
* This version data is used as a suffix of a dll file extracted from the
454+
* jar.
455+
*
456+
* @return
457+
*/
413458
public static String getVersion() {
414459

415460
URL versionFile = SnappyLoader.class

0 commit comments

Comments
 (0)