Skip to content

Commit

Permalink
Create a ZipFile in a context so it will be automatically closed
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Nov 26, 2021
1 parent 0dfb118 commit 85e305b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/edu/stanford/nlp/ui/JarFileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String showListSelectionDialog(List<String> files, Point location) {
//frame.setLocation(location);
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true);
dialog.setLocation(location);
final JList fileList = new JList(new Vector<>(files));
final JList<String> fileList = new JList<>(new Vector<>(files));
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Expand Down Expand Up @@ -126,16 +126,17 @@ public List<String> getFiles(File jarFile)
//System.out.println("Looking at " + jarFile);
List<String> files = new ArrayList<>();

ZipFile zin = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zin.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.matches(pattern)) {
files.add(name);
try (ZipFile zin = new ZipFile(jarFile)) {
Enumeration<? extends ZipEntry> entries = zin.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.matches(pattern)) {
files.add(name);
}
}
Collections.sort(files);
}
Collections.sort(files);
return files;
}
}

0 comments on commit 85e305b

Please sign in to comment.