Skip to content

Commit 1884b24

Browse files
authored
Merge pull request #455 from scijava/abstract-interface
DefaultIOService: Add concrete methods to resolve Locations, instead of forcing FileLocation Closes imagej/tutorials#101
2 parents 3e0afe1 + 9bcf527 commit 1884b24

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/main/java/org/scijava/io/DefaultIOService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ public final class DefaultIOService
6161

6262
@Parameter
6363
private LocationService locationService;
64+
65+
@Override
66+
public IOPlugin<?> getOpener(final String source) throws IOException {
67+
try {
68+
return getOpener(locationService.resolve(source));
69+
} catch (URISyntaxException e) {
70+
throw new IOException(e);
71+
}
72+
}
73+
74+
@Override
75+
public <D> IOPlugin<D> getSaver(D data, String destination) throws IOException {
76+
try {
77+
return getSaver(data, locationService.resolve(destination));
78+
} catch (URISyntaxException e) {
79+
throw new IOException(e);
80+
}
81+
}
6482

6583
@Override
6684
public Object open(final String source) throws IOException {
@@ -112,4 +130,5 @@ public void save(final Object data, final Location destination)
112130
log.error("No Saver IOPlugin found for " + data.toString() + ".");
113131
}
114132
}
133+
115134
}

src/main/java/org/scijava/io/IOService.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.io.IOException;
3333

34-
import org.scijava.io.location.FileLocation;
3534
import org.scijava.io.location.Location;
3635
import org.scijava.plugin.HandlerService;
3736
import org.scijava.service.SciJavaService;
@@ -49,9 +48,7 @@ public interface IOService extends HandlerService<Location, IOPlugin<?>>,
4948
* Gets the most appropriate {@link IOPlugin} for opening data from the given
5049
* location.
5150
*/
52-
default IOPlugin<?> getOpener(final String source) {
53-
return getOpener(new FileLocation(source));
54-
}
51+
IOPlugin<?> getOpener(final String source) throws IOException;
5552

5653
/**
5754
* Gets the most appropriate {@link IOPlugin} for opening data from the given
@@ -68,9 +65,7 @@ default IOPlugin<?> getOpener(Location source) {
6865
* Gets the most appropriate {@link IOPlugin} for saving data to the given
6966
* location.
7067
*/
71-
default <D> IOPlugin<D> getSaver(final D data, final String destination) {
72-
return getSaver(data, new FileLocation(destination));
73-
}
68+
<D> IOPlugin<D> getSaver(final D data, final String destination) throws IOException;
7469

7570
/**
7671
* Gets the most appropriate {@link IOPlugin} for saving data to the given

0 commit comments

Comments
 (0)