diff --git a/libraries/BridJ/src/main/java/org/bridj/Platform.java b/libraries/BridJ/src/main/java/org/bridj/Platform.java old mode 100644 new mode 100755 index 1304d34ba..d1ef5db2f --- a/libraries/BridJ/src/main/java/org/bridj/Platform.java +++ b/libraries/BridJ/src/main/java/org/bridj/Platform.java @@ -32,18 +32,15 @@ import org.bridj.util.ProcessUtils; import java.util.Set; -import java.util.HashSet; import java.util.regex.Pattern; import java.io.*; import java.net.URL; import java.util.List; import java.util.Collections; -import java.util.Collection; import java.util.ArrayList; import java.net.MalformedURLException; import java.net.URLClassLoader; -import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -661,47 +658,92 @@ public void run() { } static final long DELETE_OLD_BINARIES_AFTER_MILLIS = 24 * 60 * 60 * 1000; // 24 hours - static File extractEmbeddedLibraryResource(String name) throws IOException { - String firstLibraryResource = null; + /** + * Extracts a single embedded file from the a JAR, to the {@link #extractedLibrariesTempDir} directory. + *
+ * If the embedded library resource cannot be located, null is returned. + *
+ * + * @param libraryResource Path of the file in the jar to extract. + * @return If successful, the extracted File reference, otherwise null. + */ + static File extractEmbeddedResource(String libraryResource) throws IOException { + InputStream in = getResourceAsStream(libraryResource); + if (in == null) { + File f = new File(libraryResource); + if (!f.exists()) { + f = new File(f.getName()); + } + if (f.exists()) { + return f.getCanonicalFile(); + } else { + return null; + } + } + int len; + byte[] b = new byte[8196]; + String fileName = new File(libraryResource).getName(); + File libFile = new File(extractedLibrariesTempDir, fileName); + OutputStream out = new BufferedOutputStream(new FileOutputStream(libFile)); + while ((len = in.read(b)) > 0) { + out.write(b, 0, len); + } + out.close(); + in.close(); + + addTemporaryExtractedLibraryFileToDeleteOnExit(libFile); + addTemporaryExtractedLibraryFileToDeleteOnExit(libFile.getParentFile()); - List+ * Tries to extract the library based on the possible paths generated by {@link #getEmbeddedLibraryResource}. + * Additionally, if available, accompanying debug symbol files are extracted into the same folder. + *
+ *+ * If no matching library was found and extracted, null is returned. + *
+ * + * @param name Name of the library to extract (without extension). + * @return If found, a File reference to the extracted library, otherwise null. + */ + static File extractEmbeddedLibraryResource(String name) throws IOException { + List