|
21 | 21 |
|
22 | 22 | package net.imagej.table; |
23 | 23 |
|
24 | | -import io.scif.io.IRandomAccess; |
25 | | -import io.scif.io.VirtualHandle; |
26 | | -import io.scif.services.LocationService; |
27 | | - |
28 | 24 | import java.io.IOException; |
29 | 25 | import java.util.ArrayList; |
30 | 26 | import java.util.Arrays; |
|
37 | 33 |
|
38 | 34 | import org.scijava.Priority; |
39 | 35 | import org.scijava.io.AbstractIOPlugin; |
| 36 | +import org.scijava.io.DataHandle; |
| 37 | +import org.scijava.io.DataHandleService; |
| 38 | +import org.scijava.io.FileLocation; |
40 | 39 | import org.scijava.io.IOPlugin; |
| 40 | +import org.scijava.io.Location; |
41 | 41 | import org.scijava.plugin.Parameter; |
42 | 42 | import org.scijava.plugin.Plugin; |
43 | 43 | import org.scijava.util.FileUtils; |
|
51 | 51 | public class DefaultTableIOPlugin extends AbstractIOPlugin<GenericTable> { |
52 | 52 |
|
53 | 53 | @Parameter |
54 | | - private LocationService locationService; |
| 54 | + private DataHandleService dataHandleService; |
55 | 55 |
|
56 | 56 | /** Reads the first row of the input file as column headers. */ |
57 | 57 | @Parameter(required = false) |
@@ -180,12 +180,16 @@ else if (line.charAt(idx) == separator) { |
180 | 180 |
|
181 | 181 | @Override |
182 | 182 | public GenericTable open(final String source) throws IOException { |
183 | | - final IRandomAccess handle = locationService.getHandle(source); |
184 | | - if (handle instanceof VirtualHandle) { |
| 183 | + // FIXME Assumes FileLocation |
| 184 | + final Location sourceLocation = new FileLocation(source); |
| 185 | + final DataHandle<? extends Location> handle = // |
| 186 | + dataHandleService.create(sourceLocation); |
| 187 | + long length = handle.length(); |
| 188 | + if (length == 0) { |
185 | 189 | throw new IOException("Cannot open source"); |
186 | 190 | } |
187 | | - handle.seek(0); |
188 | | - final byte[] buffer = new byte[(int) handle.length()]; |
| 191 | + |
| 192 | + final byte[] buffer = new byte[(int) length]; |
189 | 193 | handle.read(buffer); |
190 | 194 | final String text = new String(buffer); |
191 | 195 |
|
@@ -248,11 +252,10 @@ public GenericTable open(final String source) throws IOException { |
248 | 252 | public void save(final GenericTable table, final String source) |
249 | 253 | throws IOException |
250 | 254 | { |
251 | | - final IRandomAccess handle = locationService.getHandle(source, true); |
252 | | - if (handle instanceof VirtualHandle) { |
253 | | - throw new IOException("Cannot open source"); |
254 | | - } |
255 | | - handle.seek(0); |
| 255 | + // FIXME Assumes FileLocation |
| 256 | + final Location sourceLocation = new FileLocation(source); |
| 257 | + final DataHandle<Location> handle = // |
| 258 | + dataHandleService.create(sourceLocation); |
256 | 259 |
|
257 | 260 | final boolean writeRH = this.writeRowHeaders && table.getRowCount() > 0 && |
258 | 261 | IntStream.range(0, table.getRowCount()).allMatch(row -> table |
|
0 commit comments