forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make file changes to download and build the dependencies .Load the shared library when RocksDB is initialized
- Loading branch information
Naveen
committed
Aug 18, 2014
1 parent
68eed8c
commit ddb8039
Showing
4 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.rocksdb; | ||
|
||
import java.io.*; | ||
|
||
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 { | ||
|
||
File temp = File.createTempFile(tempFilePrefix, tempFileSuffix); | ||
temp.deleteOnExit(); | ||
|
||
if (!temp.exists()) { | ||
throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist."); | ||
} | ||
|
||
byte[] buffer = new byte[1024]; | ||
int readBytes; | ||
|
||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(sharedLibraryName); | ||
if (is == null) { | ||
throw new FileNotFoundException(sharedLibraryName + " was not found inside JAR."); | ||
} | ||
|
||
OutputStream os = new FileOutputStream(temp); | ||
try { | ||
while ((readBytes = is.read(buffer)) != -1) { | ||
os.write(buffer, 0, readBytes); | ||
} | ||
} finally { | ||
os.close(); | ||
is.close(); | ||
} | ||
|
||
System.load(temp.getAbsolutePath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters