From ef63e4ba899bc33fef2cb7ac50067def0518f7f7 Mon Sep 17 00:00:00 2001 From: sirReeall <35725129+sirReeall@users.noreply.github.com> Date: Fri, 15 Nov 2019 12:52:00 +0000 Subject: [PATCH] unzipped files are tracked and cleaned up using file -> close --- .../jmxdumpanalyzerfx/JmxMainController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/org/alfresco/support/expert/jmxdumpanalyzerfx/JmxMainController.java b/src/main/java/org/alfresco/support/expert/jmxdumpanalyzerfx/JmxMainController.java index b56ae28..212a28a 100644 --- a/src/main/java/org/alfresco/support/expert/jmxdumpanalyzerfx/JmxMainController.java +++ b/src/main/java/org/alfresco/support/expert/jmxdumpanalyzerfx/JmxMainController.java @@ -13,8 +13,12 @@ import java.io.InputStream; import java.math.BigDecimal; import java.net.URL; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; import java.util.Enumeration; import java.util.HashSet; +import java.util.List; import java.util.Properties; import java.util.Random; import java.util.ResourceBundle; @@ -113,6 +117,8 @@ public class JmxMainController implements Initializable { private HostServices hostServices ; + + // used to gain access to pom.xml properties private static Properties jmxdump_build_properties = new Properties(); static { try { @@ -123,9 +129,11 @@ public class JmxMainController implements Initializable { } public static String version = jmxdump_build_properties.getProperty("version"); public static String githubURL = jmxdump_build_properties.getProperty("githubURL"); + public static String filePath = null; public static File file; public static File openedZipfile; + private Deque targetFileNameList = new ArrayDeque<>(); private static Set basics = new HashSet(); private static Set usergroups = new HashSet(); @@ -602,9 +610,21 @@ private void doSearch() throws IOException { @FXML // handler for menu item -> Close event private void handleClose(ActionEvent event) { + cleanup(); System.exit(0); } + + /** + * Cleans up any files or resources used by the instanace + */ + + void cleanup() { + for (File file : targetFileNameList){ + file.deleteOnExit(); + } + } + @FXML // handler for menu item -> Open JMXDump file event private void handleFileOpenAction(ActionEvent event) throws IOException { @@ -644,6 +664,8 @@ private void handleFileOpenAction(ActionEvent event) throws IOException { private void handleFileOpenZipAction(ActionEvent event) throws IOException { Boolean fileGood = true; File targetFile = new File("unzippedJMXDumpfile"+getRandomNumber()+".txt"); + // keeps track of unzipped file + targetFileNameList.add(targetFile); FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("ZIP files (*.zip)", "*.zip"); fileChooser.getExtensionFilters().add(extFilter); @@ -785,6 +807,10 @@ public void run() { try { if (file.getName().toLowerCase().endsWith(".zip")) { File unzippedFile = new File("unzippedJMXDumpfile"+getRandomNumber()+".txt"); + + //keeps track of unzipped file names + targetFileNameList.add(unzippedFile); + if (extractZipFile(new ZipFile(file), unzippedFile)){ localParse(unzippedFile.getCanonicalPath()); }