3131
3232import java .io .IOException ;
3333
34+ import org .scijava .io .location .FileLocation ;
35+ import org .scijava .io .location .Location ;
3436import org .scijava .plugin .HandlerService ;
3537import org .scijava .service .SciJavaService ;
3638
3941 *
4042 * @author Curtis Rueden
4143 */
42- public interface IOService extends HandlerService <String , IOPlugin <?>>,
44+ public interface IOService extends HandlerService <Location , IOPlugin <?>>,
4345 SciJavaService
4446{
4547
4648 /**
4749 * Gets the most appropriate {@link IOPlugin} for opening data from the given
48- * source .
50+ * location .
4951 */
5052 default IOPlugin <?> getOpener (final String source ) {
53+ return getOpener (new FileLocation (source ));
54+ }
55+
56+ /**
57+ * Gets the most appropriate {@link IOPlugin} for opening data from the given
58+ * location.
59+ */
60+ default IOPlugin <?> getOpener (Location source ) {
5161 for (final IOPlugin <?> handler : getInstances ()) {
5262 if (handler .supportsOpen (source )) return handler ;
5363 }
@@ -56,9 +66,17 @@ default IOPlugin<?> getOpener(final String source) {
5666
5767 /**
5868 * Gets the most appropriate {@link IOPlugin} for saving data to the given
59- * destination .
69+ * location .
6070 */
6171 default <D > IOPlugin <D > getSaver (final D data , final String destination ) {
72+ return getSaver (data , new FileLocation (destination ));
73+ }
74+
75+ /**
76+ * Gets the most appropriate {@link IOPlugin} for saving data to the given
77+ * location.
78+ */
79+ default <D > IOPlugin <D > getSaver (D data , Location destination ) {
6280 for (final IOPlugin <?> handler : getInstances ()) {
6381 if (handler .supportsSave (data , destination )) {
6482 @ SuppressWarnings ("unchecked" )
@@ -77,7 +95,7 @@ default <D> IOPlugin<D> getSaver(final D data, final String destination) {
7795 * The opener to use is automatically determined based on available
7896 * {@link IOPlugin}s; see {@link #getOpener(String)}.
7997 * </p>
80- *
98+ *
8199 * @param source The source (e.g., file path) from which to data should be
82100 * loaded.
83101 * @return An object representing the loaded data, or null if the source is
@@ -86,21 +104,48 @@ default <D> IOPlugin<D> getSaver(final D data, final String destination) {
86104 */
87105 Object open (String source ) throws IOException ;
88106
107+ /**
108+ * Loads data from the given location.
109+ * <p>
110+ * The opener to use is automatically determined based on available
111+ * {@link IOPlugin}s; see {@link #getOpener(Location)}.
112+ * </p>
113+ *
114+ * @param source The location from which to data should be loaded.
115+ * @return An object representing the loaded data, or null if the source is
116+ * not supported.
117+ * @throws IOException if something goes wrong loading the data.
118+ */
119+ Object open (Location source ) throws IOException ;
120+
89121 /**
90122 * Saves data to the given destination. The nature of the destination is left
91123 * intentionally general, but the most common example is a file path.
92124 * <p>
93125 * The saver to use is automatically determined based on available
94126 * {@link IOPlugin}s; see {@link #getSaver(Object, String)}.
95127 * </p>
96- *
128+ *
97129 * @param data The data to be saved to the destination.
98130 * @param destination The destination (e.g., file path) to which data should
99131 * be saved.
100132 * @throws IOException if something goes wrong saving the data.
101133 */
102134 void save (Object data , String destination ) throws IOException ;
103135
136+ /**
137+ * Saves data to the given location.
138+ * <p>
139+ * The saver to use is automatically determined based on available
140+ * {@link IOPlugin}s; see {@link #getSaver(Object, Location)}.
141+ * </p>
142+ *
143+ * @param data The data to be saved to the destination.
144+ * @param destination The destination location to which data should be saved.
145+ * @throws IOException if something goes wrong saving the data.
146+ */
147+ void save (Object data , Location destination ) throws IOException ;
148+
104149 // -- HandlerService methods --
105150
106151 @ Override
@@ -110,7 +155,7 @@ default Class<IOPlugin<?>> getPluginType() {
110155 }
111156
112157 @ Override
113- default Class <String > getType () {
114- return String .class ;
158+ default Class <Location > getType () {
159+ return Location .class ;
115160 }
116161}
0 commit comments