Update NativeUtils.java
Refactor function loadLibraryFromJar
This commit is contained in:
parent
ec83d01dca
commit
0df138171c
|
@ -91,22 +91,24 @@ public final class NativeUtils {
|
||||||
* 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);
|
||||||
|
try {
|
||||||
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
|
copyResourceToFile(path, tempFile);
|
||||||
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue