Skip to content

Commit

Permalink
unzipped files are tracked and cleaned up using file -> close
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandalorian committed Nov 15, 2019
1 parent 7a8a545 commit ef63e4b
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<File> targetFileNameList = new ArrayDeque<>();

private static Set<String> basics = new HashSet<String>();
private static Set<String> usergroups = new HashSet<String>();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit ef63e4b

Please sign in to comment.