Skip to content

Commit cf7ace8

Browse files
author
Naveen
committed
Addressing review comments
1 parent 1d284db commit cf7ace8

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

java/org/rocksdb/NativeLibraryLoader.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import java.io.*;
44

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+
*/
510
public class NativeLibraryLoader {
611

712
private static String sharedLibraryName = "librocksdbjni.so";
813
private static String tempFilePrefix = "librocksdbjni";
914
private static String tempFileSuffix = ".so";
10-
/**
11-
* Private constructor - this class will never be instanced
12-
*/
13-
private NativeLibraryLoader() {
14-
}
1515

1616
public static void loadLibraryFromJar()
1717
throws IOException {
@@ -23,16 +23,16 @@ public static void loadLibraryFromJar()
2323
throw new RuntimeException("File " + temp.getAbsolutePath() + " does not exist.");
2424
}
2525

26-
byte[] buffer = new byte[1024];
26+
byte[] buffer = new byte[102400];
2727
int readBytes;
2828

2929
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(sharedLibraryName);
3030
if (is == null) {
3131
throw new RuntimeException(sharedLibraryName + " was not found inside JAR.");
3232
}
3333

34-
OutputStream os = new FileOutputStream(temp);
3534
try {
35+
OutputStream os = new FileOutputStream(temp);
3636
while ((readBytes = is.read(buffer)) != -1) {
3737
os.write(buffer, 0, readBytes);
3838
}
@@ -43,4 +43,9 @@ public static void loadLibraryFromJar()
4343

4444
System.load(temp.getAbsolutePath());
4545
}
46+
/**
47+
* Private constructor to disallow instantiation
48+
*/
49+
private NativeLibraryLoader() {
50+
}
4651
}

java/org/rocksdb/RocksDB.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class RocksDB extends RocksObject {
2626
"snappy", "z", "bzip2", "lz4", "lz4hc"};
2727

2828
static {
29-
loadLibrary();
29+
RocksDB.loadLibrary();
3030
}
3131

3232

0 commit comments

Comments
 (0)