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,52 @@ 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+ default Object open (Location source ) throws IOException {
120+ throw new UnsupportedOperationException ();
121+ }
122+
89123 /**
90124 * Saves data to the given destination. The nature of the destination is left
91125 * intentionally general, but the most common example is a file path.
92126 * <p>
93127 * The saver to use is automatically determined based on available
94128 * {@link IOPlugin}s; see {@link #getSaver(Object, String)}.
95129 * </p>
96- *
130+ *
97131 * @param data The data to be saved to the destination.
98132 * @param destination The destination (e.g., file path) to which data should
99133 * be saved.
100134 * @throws IOException if something goes wrong saving the data.
101135 */
102136 void save (Object data , String destination ) throws IOException ;
103137
138+ /**
139+ * Saves data to the given location.
140+ * <p>
141+ * The saver to use is automatically determined based on available
142+ * {@link IOPlugin}s; see {@link #getSaver(Object, Location)}.
143+ * </p>
144+ *
145+ * @param data The data to be saved to the destination.
146+ * @param destination The destination location to which data should be saved.
147+ * @throws IOException if something goes wrong saving the data.
148+ */
149+ default void save (Object data , Location destination ) throws IOException {
150+ throw new UnsupportedOperationException ();
151+ }
152+
104153 // -- HandlerService methods --
105154
106155 @ Override
@@ -110,7 +159,7 @@ default Class<IOPlugin<?>> getPluginType() {
110159 }
111160
112161 @ Override
113- default Class <String > getType () {
114- return String .class ;
162+ default Class <Location > getType () {
163+ return Location .class ;
115164 }
116165}
0 commit comments