8000 DefaultTableIOPlugin: stop assuming FileService · scijava/scijava-plugins-io-table@6e4ba23 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit 6e4ba23

Browse files
committed
DefaultTableIOPlugin: stop assuming FileService
We now use the LocationService's resolve(String) method to magically transform the string into a Location. And fail fast if it doesn't work.
1 parent 945feda commit 6e4ba23

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
package org.scijava.table;
3232

33+
import java.net.URISyntaxException;
3334
import java.io.IOException;
3435
import java.util.ArrayList;
3536
import java.util.Arrays;
@@ -42,11 +43,11 @@
4243

4344
import org.scijava.Priority;
4445
import org.scijava.io.AbstractIOPlugin;
46+
import org.scijava.io.IOPlugin;
4547
import org.scijava.io.handle.DataHandle;
4648
import org.scijava.io.handle.DataHandleService;
47-
import org.scijava.io.location.FileLocation;
48-
import org.scijava.io.IOPlugin;
4949
import org.scijava.io.location.Location;
50+
import org.scijava.io.location.LocationService;
5051
import org.scijava.plugin.Parameter;
5152
import org.scijava.plugin.Plugin;
5253
import org.scijava.util.FileUtils;
@@ -60,6 +61,9 @@
6061
@Plugin(type = IOPlugin.class, priority = Priority.LOW)
6162
public class DefaultTableIOPlugin extends AbstractIOPlugin<Table> {
6263

64+
@Parameter
65+
private LocationService locationService;
66+
6367
@Parameter
6468
private DataHandleService dataHandleService;
6569

@@ -190,8 +194,13 @@ else if (line.charAt(idx) == separator) {
190194

191195
@Override
192196
public GenericTable open(final String source) throws IOException {
193-
// FIXME Assumes FileLocation
194-
final Location sourceLocation = new FileLocation(source);
197+
final Location sourceLocation;
198+
try {
199+
sourceLocation = locationService.resolve(source);
200+
}
201+
catch (final URISyntaxException exc) {
202+
throw new IOException("Unresolvable source: " + source, exc);
203+
}
195204
final GenericTable table = new DefaultGenericTable();
196205

197206
try (final DataHandle<? extends Location> handle = //
@@ -266,8 +275,13 @@ public GenericTable open(final String source) throws IOException {
266275
public void save(final Table table, final String destination)
267276
throws IOException
268277
{
269-
// FIXME Assumes FileLocation
270-
final Location dstLocation = new FileLocation(destination);
278+
final Location dstLocation;
279+
try {
280+
dstLocation = locationService.resolve(destination);
281+
}
282+
catch (final URISyntaxException exc) {
283+
throw new IOException("Unresolvable destination: " + destination, exc);
284+
}
271285

272286
try (final DataHandle<Location> handle = //
273287
dataHandleService.create(dstLocation))

0 commit comments

Comments
 (0)
0