From f1c3b09a2fa379270770e5474c99d95c7a145fd3 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Sun, 4 Aug 2024 08:52:14 -0400 Subject: [PATCH] snaploader-examples: applied API changes --- .../snaploader/examples/TestFilesystemMemoryLeak.java | 5 +++++ .../snaploader/examples/TestMultiThreading.java | 2 +- .../snaploader/examples/TestZipExtractor.java | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestFilesystemMemoryLeak.java b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestFilesystemMemoryLeak.java index f2f4295..848f044 100644 --- a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestFilesystemMemoryLeak.java +++ b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestFilesystemMemoryLeak.java @@ -37,6 +37,8 @@ import electrostatic.snaploader.filesystem.FileLocator; import electrostatic.snaploader.filesystem.ZipCompressionType; import electrostatic.snaploader.platform.util.PropertiesProvider; +import electrostatic.snaploader.util.SnapLoaderLogger; + import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -49,9 +51,12 @@ public class TestFilesystemMemoryLeak { public static void main(String[] args) throws IOException { /* Locates the image inside the Zip Compression */ + SnapLoaderLogger.setLoggingEnabled(true); final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP); /* Extracts the image filesystem from the Zip Compression */ final FileExtractor fileExtractor = new FileExtractor(fileLocator, getExtractionPath()); + fileLocator.initialize(0); + fileExtractor.initialize(0); /* CLOSE/CLEAR I/O Resources */ fileExtractor.setExtractionListener(new FileExtractionListener() { @Override diff --git a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestMultiThreading.java b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestMultiThreading.java index e25913c..3ae9571 100644 --- a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestMultiThreading.java +++ b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestMultiThreading.java @@ -37,7 +37,7 @@ import electrostatic.snaploader.LoadingCriterion; import electrostatic.snaploader.ConcurrentNativeBinaryLoader; -import electrostatic.snaploader.UnSupportedSystemError; +import electrostatic.snaploader.throwable.UnSupportedSystemError; import electrostatic.snaploader.platform.util.DefaultDynamicLibraries; import electrostatic.snaploader.platform.NativeDynamicLibrary; diff --git a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestZipExtractor.java b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestZipExtractor.java index 27d7b5d..69231bf 100644 --- a/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestZipExtractor.java +++ b/snaploader-examples/src/main/java/electrostatic/snaploader/examples/TestZipExtractor.java @@ -41,6 +41,7 @@ import electrostatic.snaploader.filesystem.FileLocator; import electrostatic.snaploader.filesystem.ZipCompressionType; import electrostatic.snaploader.platform.util.PropertiesProvider; +import electrostatic.snaploader.throwable.FilesystemResourceScavengingException; /** * Tests extracting an image compression from a Zip compression type filesystem using {@link FileExtractor} API. @@ -54,6 +55,8 @@ public static void main(String[] args) throws IOException { final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP); /* Extracts the image filesystem from the Zip Compression */ final FileExtractor fileExtractor = new FileExtractor(fileLocator, getExtractionPath()); + fileLocator.initialize(0); + fileExtractor.initialize(0); /* CLOSE/CLEAR I/O Resources */ fileExtractor.setExtractionListener(new FileExtractionListener() { @Override @@ -70,11 +73,8 @@ public void onExtractionFailure(FileExtractor fileExtractor, Throwable throwable public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fileLocator) { try { fileExtractor.close(); - fileLocator.close(); - Logger.getLogger(TestZipExtractor.class.getName()) - .log(Level.INFO, "Filesystem Resources Closed!"); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (Exception e) { + throw new FilesystemResourceScavengingException(e); } } });