3030package org .scijava .io ;
3131
3232import java .io .IOException ;
33+ import java .net .URISyntaxException ;
3334
3435import org .scijava .io .location .FileLocation ;
3536import org .scijava .io .location .Location ;
37+ import org .scijava .io .location .LocationService ;
3638import org .scijava .plugin .HandlerPlugin ;
3739import org .scijava .plugin .Plugin ;
3840
@@ -58,22 +60,32 @@ public interface IOPlugin<D> extends HandlerPlugin<Location> {
5860 /** Checks whether the I/O plugin can open data from the given source. */
5961 @ SuppressWarnings ("unused" )
6062 default boolean supportsOpen (final String source ) {
61- return supportsOpen (new FileLocation (source ));
63+ try {
64+ return supportsOpen (context ().service (LocationService .class ).resolve (source ));
65+ }
66+ catch (final URISyntaxException exc ) {
67+ return false ;
68+ }
6269 }
6370
6471 /** Checks whether the I/O plugin can open data from the given location. */
65- default boolean supportsOpen (Location source ) {
72+ default boolean supportsOpen (final Location source ) {
6673 return false ;
6774 }
6875
6976 /** Checks whether the I/O plugin can save data to the given destination. */
7077 @ SuppressWarnings ("unused" )
7178 default boolean supportsSave (final String destination ) {
72- return supportsSave (new FileLocation (destination ));
79+ try {
80+ return supportsSave (context ().service (LocationService .class ).resolve (destination ));
81+ }
82+ catch (final URISyntaxException exc ) {
83+ return false ;
84+ }
7385 }
7486
7587 /** Checks whether the I/O plugin can save data to the given location. */
76- default boolean supportsSave (Location destination ) {
88+ default boolean supportsSave (final Location destination ) {
7789 return false ;
7890 }
7991
@@ -85,7 +97,7 @@ default boolean supportsSave(final Object data, final String destination) {
8597 return supportsSave (destination ) && getDataType ().isInstance (data );
8698 }
8799
88- default boolean supportsSave (Object data , Location destination ) {
100+ default boolean supportsSave (final Object data , final Location destination ) {
89101 return supportsSave (destination ) && getDataType ().isInstance (data );
90102 }
91103
@@ -96,17 +108,23 @@ default D open(final String source) throws IOException {
96108 }
97109
98110 /** Opens data from the given location. */
99- default D open (Location source ) throws IOException {
111+ default D open (final Location source ) throws IOException {
100112 throw new UnsupportedOperationException ();
101113 }
114+
102115 /** Saves the given data to the specified destination. */
103116 @ SuppressWarnings ("unused" )
104117 default void save (final D data , final String destination ) throws IOException {
105- save (data , new FileLocation (destination ));
118+ try {
119+ save (data , context ().service (LocationService .class ).resolve (destination ));
120+ }
121+ catch (final URISyntaxException exc ) {
122+ throw new UnsupportedOperationException (exc );
123+ }
106124 }
107125
108126 /** Saves the given data to the specified location. */
109- default void save (D data , Location destination ) throws IOException {
127+ default void save (final D data , final Location destination ) throws IOException {
110128 throw new UnsupportedOperationException ();
111129 }
112130
0 commit comments