mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 18:21:51 +01:00
Merge 9eb5089eae
into 72eda9a24f
This commit is contained in:
commit
48922ae405
@ -45,6 +45,9 @@ public final class NativeUtils {
|
|||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
temp.delete();
|
temp.delete();
|
||||||
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
|
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
file.delete();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
@ -90,24 +93,26 @@ public final class NativeUtils {
|
|||||||
* @throws FileNotFoundException If the file could not be found inside the
|
* @throws FileNotFoundException If the file could not be found inside the
|
||||||
* JAR.
|
* JAR.
|
||||||
*/
|
*/
|
||||||
public static void loadLibraryFromJar(String path) throws IOException {
|
public static void loadLibraryFromJar(String path) throws IOException {
|
||||||
File temp = unpackLibraryFromJarInternal(path);
|
File tempFile = unpackLibraryFromJarInternal(path);
|
||||||
|
copyResourceToFile(path, tempFile);
|
||||||
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
|
try {
|
||||||
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
System.load(tempFile.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} finally {
|
||||||
temp.delete();
|
tempFile.deleteOnExit();
|
||||||
throw e;
|
}
|
||||||
} catch (NullPointerException e) {
|
|
||||||
temp.delete();
|
|
||||||
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
private static void copyResourceToFile(String resourcePath, File file) throws IOException {
|
||||||
System.load(temp.getAbsolutePath());
|
try ( InputStream inputStream = NativeUtils.class.getResourceAsStream(resourcePath)) {
|
||||||
} finally {
|
Files.copy(inputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
temp.deleteOnExit();
|
} catch (IOException e) {
|
||||||
}
|
file.delete();
|
||||||
|
throw e;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
file.delete();
|
||||||
|
throw new FileNotFoundException("File " + resourcePath + " was not found inside JAR.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File createTempDirectory(String prefix) throws IOException {
|
private static File createTempDirectory(String prefix) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user