Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Naveen committed Sep 23, 2014
1 parent 1d284db commit cf7ace8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions java/org/rocksdb/NativeLibraryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import java.io.*;


/**
* This class is used to load the RocksDB shared library from within the jar.
* The shared library is extracted to a temp folder and loaded from there.
*/
public class NativeLibraryLoader {

private static String sharedLibraryName = "librocksdbjni.so";
private static String tempFilePrefix = "librocksdbjni";
private static String tempFileSuffix = ".so";
/**
* Private constructor - this class will never be instanced
*/
private NativeLibraryLoader() {
}

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

byte[] buffer = new byte[1024];
byte[] buffer = new byte[102400];
int readBytes;

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

OutputStream os = new FileOutputStream(temp);
try {
OutputStream os = new FileOutputStream(temp);
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
Expand All @@ -43,4 +43,9 @@ public static void loadLibraryFromJar()

System.load(temp.getAbsolutePath());
}
/**
* Private constructor to disallow instantiation
*/
private NativeLibraryLoader() {
}
}
2 changes: 1 addition & 1 deletion java/org/rocksdb/RocksDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RocksDB extends RocksObject {
"snappy", "z", "bzip2", "lz4", "lz4hc"};

static {
loadLibrary();
RocksDB.loadLibrary();
}


Expand Down

0 comments on commit cf7ace8

Please sign in to comment.