diff --git a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestBasicFeatures.java b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestBasicFeatures.java index 1c921cd..98f70e5 100644 --- a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestBasicFeatures.java +++ b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestBasicFeatures.java @@ -35,6 +35,7 @@ import com.avrsandbox.snaploader.LibraryInfo; import com.avrsandbox.snaploader.NativeBinaryLoader; import com.avrsandbox.snaploader.platform.NativeVariant; +import com.avrsandbox.snaploader.platform.PropertiesProvider; import com.avrsandbox.snaploader.LoadingCriterion; /** @@ -43,17 +44,11 @@ * @author pavl_g */ public final class TestBasicFeatures { - - protected static final String userdir = System.getProperty("user.dir"); - protected static final String fileSeparator = System.getProperty("file.separator"); - protected static final String jar = "jme3-alloc-desktop-1.0.0-pre-gamma-2.jar"; - protected static final String libraryBasename = "jmealloc"; - - protected static final String libraryAbsolutePath = userdir + fileSeparator + "libs"; - protected static final String jarFile = libraryAbsolutePath + fileSeparator + jar; - protected static final LibraryInfo libraryInfo = new LibraryInfo(jarFile, null, libraryBasename, libraryAbsolutePath); - - protected static final String finalAbsolutePath = libraryAbsolutePath + fileSeparator + "libjmealloc.so"; + + protected static final LibraryInfo libraryInfo = new LibraryInfo(getJarFile(), + null, + getLibraryBaseName(), + getLibrariesAbsolutePath()); protected static NativeBinaryLoader loader; @@ -81,4 +76,28 @@ protected static void printDetails(NativeBinaryLoader loader) { System.out.println("Is Extracted: " + loader.getNativeDynamicLibrary().isExtracted()); System.out.println("--------------------------------------------------------------"); } + + protected static String getLibrariesAbsolutePath() { + return PropertiesProvider.USER_DIR.getSystemProperty() + + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "libs"; + } + + protected static String getJarFilePath() { + return getLibrariesAbsolutePath() + + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getJarFile(); + } + + protected static String getNativeDynamicLibraryPath() { + return getLibrariesAbsolutePath() + + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + + "lib" + getLibraryBaseName() + ".so"; + } + + protected static String getJarFile() { + return "jme3-alloc-desktop-1.0.0-pre-gamma-2.jar"; + } + + protected static String getLibraryBaseName() { + return "jmealloc"; + } } \ No newline at end of file diff --git a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestMultipleLoads.java b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestMultipleLoads.java index 3ac8a0d..461b0f4 100644 --- a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestMultipleLoads.java +++ b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestMultipleLoads.java @@ -43,10 +43,10 @@ public final class TestMultipleLoads { public static void main(String[] args) throws InterruptedException, IOException { TestBasicFeatures.main(args); - new File(TestBasicFeatures.finalAbsolutePath).delete(); + new File(TestBasicFeatures.getNativeDynamicLibraryPath()).delete(); Thread.sleep(5000); TestBasicFeatures.main(args); - new File(TestBasicFeatures.finalAbsolutePath).delete(); + new File(TestBasicFeatures.getNativeDynamicLibraryPath()).delete(); Thread.sleep(5000); TestBasicFeatures.main(args); } diff --git a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestZipExtractor.java b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestZipExtractor.java index eed82da..0bc3fb5 100644 --- a/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestZipExtractor.java +++ b/snaploader-examples/src/main/java/com/avrsandbox/snaploader/examples/TestZipExtractor.java @@ -35,6 +35,7 @@ import com.avrsandbox.snaploader.file.FileExtractor; import com.avrsandbox.snaploader.file.FileLocator; import com.avrsandbox.snaploader.file.ZipCompressionType; +import com.avrsandbox.snaploader.platform.PropertiesProvider; /** * Tests extracting an image compression from a Zip compression type file using {@link FileExtractor} API. @@ -42,15 +43,37 @@ * @author pavl_g */ public class TestZipExtractor { - - protected static final String directory = TestBasicFeatures.libraryAbsolutePath + TestBasicFeatures.fileSeparator + "jmelogo700.zip"; - protected static final String destination = TestBasicFeatures.libraryAbsolutePath + TestBasicFeatures.fileSeparator + "jmelogo700.png"; - + public static void main(String[] args) throws IOException { /* Locates the image inside the Zip Compression */ - final FileLocator fileLocator = new FileLocator(directory, "jmelogo700.png", ZipCompressionType.ZIP); + final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP); /* Extracts the image file from the Zip Compression */ - final FileExtractor fileExtractor = new FileExtractor(fileLocator, destination); + final FileExtractor fileExtractor = new FileExtractor(fileLocator, getExtractionPath()); + /* CLOSE/CLEAR I/O Resources */ + fileExtractor.setExtractionListener(() -> clearResources(fileExtractor)); fileExtractor.extract(); } + + protected static String getZipAbsolutePath() { + return TestBasicFeatures.getLibrariesAbsolutePath() + + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip"; + } + + protected static String getExtractionPath() { + return TestBasicFeatures.getLibrariesAbsolutePath() + + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath(); + } + + protected static String getFilePath() { + return "jmelogo700.png"; + } + + private static void clearResources(FileExtractor fileExtractor) { + try { + fileExtractor.getFileLocator().close(); + fileExtractor.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } }