forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/facebook/rocksdb
- Loading branch information
Showing
28 changed files
with
422 additions
and
115 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
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
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
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
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
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
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,58 @@ | ||
package org.rocksdb; | ||
|
||
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"; | ||
|
||
public static void loadLibraryFromJar(String tmpDir) | ||
throws IOException { | ||
File temp; | ||
if(tmpDir == null || tmpDir.equals("")) | ||
temp = File.createTempFile(tempFilePrefix, tempFileSuffix); | ||
else | ||
temp = new File(tmpDir + "/" + sharedLibraryName); | ||
|
||
temp.deleteOnExit(); | ||
|
||
if (!temp.exists()) { | ||
throw new RuntimeException("File " + temp.getAbsolutePath() + " does not exist."); | ||
} | ||
|
||
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 = null; | ||
try { | ||
os = new FileOutputStream(temp); | ||
while ((readBytes = is.read(buffer)) != -1) { | ||
os.write(buffer, 0, readBytes); | ||
} | ||
} finally { | ||
if(os != null) | ||
os.close(); | ||
|
||
if(is != null) | ||
is.close(); | ||
} | ||
|
||
System.load(temp.getAbsolutePath()); | ||
} | ||
/** | ||
* Private constructor to disallow instantiation | ||
*/ | ||
private NativeLibraryLoader() { | ||
} | ||
} |
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
Oops, something went wrong.