3131package org .scijava .table .io ;
3232
3333import java .io .IOException ;
34+ import java .net .URISyntaxException ;
3435
36+ import org .scijava .io .AbstractTypedIOService ;
3537import org .scijava .io .IOPlugin ;
3638import org .scijava .io .IOService ;
39+ import org .scijava .io .location .Location ;
3740import org .scijava .plugin .Parameter ;
3841import org .scijava .plugin .Plugin ;
39- import org .scijava .service .AbstractService ;
4042import org .scijava .service .Service ;
4143import org .scijava .table .Table ;
4244
4345@ Plugin (type = Service .class )
44- public class DefaultTableIOService extends AbstractService implements
46+ public class DefaultTableIOService extends AbstractTypedIOService < Table <?, ?>> implements
4547 TableIOService
4648{
4749
48- @ Parameter
49- private IOService ioService ;
50-
5150 @ Override
52- public boolean canOpen (String source ) {
53- IOPlugin <?> opener = ioService .getOpener (source );
51+ public boolean canOpen (Location source ) {
52+ IOPlugin <?> opener = ioService () .getOpener (source );
5453 if (opener == null ) return false ;
5554 return Table .class .isAssignableFrom (opener .getDataType ());
5655 }
5756
5857 @ Override
59- public boolean canSave (Table <?, ?> table , String destination ) {
60- IOPlugin <Table <?, ?>> saver = ioService .getSaver (table , destination );
61- if (saver == null ) return false ;
62- return saver .supportsSave (destination );
63- }
64-
65- @ Override
66- public Table <?, ?> open (String source ) throws IOException {
67- IOPlugin <?> opener = ioService .getOpener (source );
68- if (opener != null && Table .class .isAssignableFrom (opener .getDataType ())) {
69- return (Table <?, ?>) opener .open (source );
58+ public Table <?, ?> open (String source , TableIOOptions options ) throws IOException {
59+ try {
60+ return open (locationService ().resolve (source ), options );
61+ } catch (URISyntaxException e ) {
62+ throw new IOException (e );
7063 }
71- throw new UnsupportedOperationException ("No compatible opener found." );
7264 }
7365
7466 @ Override
75- public Table <?, ?> open (String source , TableIOOptions options ) throws IOException {
76- IOPlugin <?> opener = ioService .getOpener (source );
67+ public Table <?, ?> open (Location source , TableIOOptions options ) throws IOException {
68+ IOPlugin <?> opener = ioService () .getOpener (source );
7769 if (opener != null && Table .class .isAssignableFrom (opener .getDataType ())
7870 && TableIOPlugin .class .isAssignableFrom (opener .getClass ())) {
7971 return ((TableIOPlugin )opener ).open (source , options );
@@ -82,24 +74,23 @@ public boolean canSave(Table<?, ?> table, String destination) {
8274 }
8375
8476 @ Override
85- public void save (Table <?, ?> table , String destination ) throws IOException {
86- IOPlugin <Table <?, ?>> saver = ioService .getSaver (table , destination );
87- if (saver != null ) {
88- saver .save (table , destination );
89- }
90- else {
91- throw new UnsupportedOperationException ("No compatible saver found." );
77+ public void save (Table <?, ?> table , String destination , TableIOOptions options ) throws IOException {
78+ try {
79+ save (table , locationService ().resolve (destination ), options );
80+ } catch (URISyntaxException e ) {
81+ throw new IOException (e );
9282 }
9383 }
9484
9585 @ Override
96- public void save (Table <?, ?> table , String destination , TableIOOptions options ) throws IOException {
97- IOPlugin <Table > saver = ioService .getSaver (table , destination );
86+ public void save (Table <?, ?> table , Location destination , TableIOOptions options ) throws IOException {
87+ IOPlugin <Table > saver = ioService () .getSaver (table , destination );
9888 if (saver != null && TableIOPlugin .class .isAssignableFrom (saver .getClass ())) {
9989 ((TableIOPlugin )saver ).save (table , destination , options );
10090 }
10191 else {
10292 throw new UnsupportedOperationException ("No compatible saver found." );
10393 }
10494 }
95+
10596}
0 commit comments