Skip to content

Commit

Permalink
Copy libs to JAVA temp folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolosnjaji committed Jul 14, 2024
1 parent 97a6a9a commit e8dfdb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/java/com/nkolosnjaji/webp/imageio/OsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@ public static Path getPathLibWebP() {

private static Path getLibPath(String libName) {
SupportedOs os = SupportedOs.getCurrent();
Path tempLocation = Path.of("/tmp/webp-java-imageio/lib/%s.%s".formatted(libName, os.suffix));
try {
Files.createDirectories(tempLocation.getParent());
} catch (IOException e) {
throw new WebPInitException(e);
}

try (InputStream lib = OsUtils.class.getResourceAsStream(getClassPathResource(libName, os))) {
Path tempLocation = Files.createTempFile(libName,os.suffix);
if (lib != null) {
Files.copy(lib, tempLocation, StandardCopyOption.REPLACE_EXISTING);
tempLocation.toFile().deleteOnExit();
return tempLocation;
}
else throw new WebPInitException("Not found");
} catch (IOException e) {
throw new WebPInitException(e);
}
tempLocation.toFile().deleteOnExit();
return tempLocation;

}

private static String getClassPathResource(String libName, SupportedOs os) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public WebPInitException(String message) {
public WebPInitException(Throwable throwable) {
super("WebP java init failed", throwable);
}

public WebPInitException(String message, Throwable throwable) {
super(message, throwable);
}
}

0 comments on commit e8dfdb3

Please sign in to comment.