Compare commits

...

4 Commits

Author SHA1 Message Date
Mohanned Anwar
3f9474207f
Merge 9eb5089eae into fb54d8b549 2023-05-22 17:37:52 -05:00
Mohanned Anwar
9eb5089eae
Update NativeUtils.java
move function
2023-04-05 10:16:48 +03:00
Mohanned Anwar
c51fe59e2f
Update NativeUtils.java
Catch the rest of the exceptions
2023-04-05 10:13:47 +03:00
Mohanned Anwar
0df138171c
Update NativeUtils.java
Refactor function loadLibraryFromJar
2023-04-02 05:41:34 +03:00

View File

@ -45,6 +45,9 @@ public final class NativeUtils {
} catch (NullPointerException e) {
temp.delete();
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
} catch (Exception e) {
file.delete();
throw e;
}
return temp;
@ -91,22 +94,24 @@ public final class NativeUtils {
* JAR.
*/
public static void loadLibraryFromJar(String path) throws IOException {
File temp = unpackLibraryFromJarInternal(path);
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
temp.delete();
throw e;
} catch (NullPointerException e) {
temp.delete();
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
File tempFile = unpackLibraryFromJarInternal(path);
copyResourceToFile(path, tempFile);
try {
System.load(tempFile.getAbsolutePath());
} finally {
tempFile.deleteOnExit();
}
}
try {
System.load(temp.getAbsolutePath());
} finally {
temp.deleteOnExit();
private static void copyResourceToFile(String resourcePath, File file) throws IOException {
try ( InputStream inputStream = NativeUtils.class.getResourceAsStream(resourcePath)) {
Files.copy(inputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
file.delete();
throw e;
} catch (NullPointerException e) {
file.delete();
throw new FileNotFoundException("File " + resourcePath + " was not found inside JAR.");
}
}