Skip to content

Commit 27c083f

Browse files
committed
DefaultTableIOPlugin: fix up the supports* logic
This change removes redundant method overrides, and fixes a bug in supportsSave where non-existent files weren't recognized. See https://forum.image.sc/t/72291.
1 parent 4bcdabe commit 27c083f

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

src/main/java/org/scijava/table/io/DefaultTableIOPlugin.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,17 @@ public class DefaultTableIOPlugin extends AbstractIOPlugin<Table> implements
7878
@Override
7979
public boolean supportsOpen(final Location source) {
8080
if (!(source instanceof FileLocation)) return false;
81-
return supportsOpen(((FileLocation) source).getFile());
82-
}
83-
84-
@Override
85-
public boolean supportsOpen(final String source) {
86-
return supportsOpen(new File(source));
87-
}
88-
89-
@Override
90-
public boolean supportsSave(final Object data, final String destination) {
91-
return supports(destination) && //
92-
Table.class.isAssignableFrom(data.getClass());
81+
final File file = ((FileLocation) source).getFile();
82+
// NB: For opening, the file must exist or it's not readable.
83+
return file.exists() && supportsFile(file);
9384
}
9485

9586
@Override
9687
public boolean supportsSave(final Location source) {
97-
return supportsOpen(source);
98-
}
99-
100-
@Override
101-
public boolean supportsSave(final String source) {
102-
return supportsOpen(source);
88+
if (!(source instanceof FileLocation)) return false;
89+
final File file = ((FileLocation) source).getFile();
90+
// NB: For saving, it's OK if the file does not exist yet.
91+
return supportsFile(file);
10392
}
10493

10594
/**
@@ -281,8 +270,8 @@ public void save(final Table table, final Location destination,
281270
save(table, destination, options.values);
282271
}
283272

284-
private boolean supportsOpen(final File file) {
285-
if (!file.exists() || file.isDirectory()) return false;
273+
private boolean supportsFile(final File file) {
274+
if (file.isDirectory()) return false;
286275
final String ext = FileUtils.getExtension(file).toLowerCase();
287276
return SUPPORTED_EXTENSIONS.contains(ext);
288277
}

src/test/java/org/scijava/table/io/DefaultTableIOPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void tearDown() {
9393
public void testSupports() throws IOException {
9494
// Non-existent .csv file: supports save, but not open.
9595
final File nonExistentCSV = new File("thisFileDoesNotExist.csv");
96-
assertSupports(nonExistentCSV, false, /*true*/false);
96+
assertSupports(nonExistentCSV, false, true);
9797

9898
// Existing .txt file: supports both open and save.
9999
final File existingTXT = createTempFile("existing");

0 commit comments

Comments
 (0)