2
2
3
3
import java .io .*;
4
4
5
+
6
+ /**
7
+ * This class is used to load the RocksDB shared library from within the jar.
8
+ * The shared library is extracted to a temp folder and loaded from there.
9
+ */
5
10
public class NativeLibraryLoader {
6
11
7
12
private static String sharedLibraryName = "librocksdbjni.so" ;
8
13
private static String tempFilePrefix = "librocksdbjni" ;
9
14
private static String tempFileSuffix = ".so" ;
10
- /**
11
- * Private constructor - this class will never be instanced
12
- */
13
- private NativeLibraryLoader () {
14
- }
15
15
16
16
public static void loadLibraryFromJar ()
17
17
throws IOException {
@@ -23,16 +23,16 @@ public static void loadLibraryFromJar()
23
23
throw new RuntimeException ("File " + temp .getAbsolutePath () + " does not exist." );
24
24
}
25
25
26
- byte [] buffer = new byte [1024 ];
26
+ byte [] buffer = new byte [102400 ];
27
27
int readBytes ;
28
28
29
29
InputStream is = ClassLoader .getSystemClassLoader ().getResourceAsStream (sharedLibraryName );
30
30
if (is == null ) {
31
31
throw new RuntimeException (sharedLibraryName + " was not found inside JAR." );
32
32
}
33
33
34
- OutputStream os = new FileOutputStream (temp );
35
34
try {
35
+ OutputStream os = new FileOutputStream (temp );
36
36
while ((readBytes = is .read (buffer )) != -1 ) {
37
37
os .write (buffer , 0 , readBytes );
38
38
}
@@ -43,4 +43,9 @@ public static void loadLibraryFromJar()
43
43
44
44
System .load (temp .getAbsolutePath ());
45
45
}
46
+ /**
47
+ * Private constructor to disallow instantiation
48
+ */
49
+ private NativeLibraryLoader () {
50
+ }
46
51
}
0 commit comments