39
39
import java .security .NoSuchAlgorithmException ;
40
40
import java .security .ProtectionDomain ;
41
41
import java .util .ArrayList ;
42
+ import java .util .Enumeration ;
42
43
import java .util .List ;
43
44
import java .util .Properties ;
44
45
84
85
*/
85
86
public class SnappyLoader
86
87
{
88
+ public static final String SNAPPY_SYSTEM_PROPERTIES_FILE = "org-xerial-snappy.properties" ;
87
89
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path" ;
88
90
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name" ;
89
91
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir" ;
@@ -93,6 +95,42 @@ public class SnappyLoader
93
95
private static boolean isLoaded = false ;
94
96
private static SnappyNativeAPI api = null ;
95
97
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
+
96
134
private static ClassLoader getRootClassLoader () {
97
135
ClassLoader cl = Thread .currentThread ().getContextClassLoader ();
98
136
while (cl .getParent () != null ) {
@@ -407,9 +445,16 @@ static File findNativeLibrary() {
407
445
}
408
446
}
409
447
410
- return null ; // Use a pre-installed snappyjava
448
+ return null ; // Use a pre-installed libsnappyjava
411
449
}
412
450
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
+ */
413
458
public static String getVersion () {
414
459
415
460
URL versionFile = SnappyLoader .class
0 commit comments