Skip to content

Commit e2a0b3f

Browse files
authored
Merge pull request #323 from scijava/more-handles-multifile2
Add test if a handle exists
2 parents 562c402 + 6a287ef commit e2a0b3f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/org/scijava/io/handle/DataHandleService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
package org.scijava.io.handle;
3434

35+
import java.io.IOException;
36+
3537
import org.scijava.io.IOService;
3638
import org.scijava.io.location.Location;
3739
import org.scijava.plugin.WrapperService;
@@ -63,4 +65,18 @@ default Class<DataHandle<Location>> getPluginType() {
6365
default Class<Location> getType() {
6466
return Location.class;
6567
}
68+
69+
/**
70+
* Convenience method to test whether it describes an existing file.
71+
*
72+
* @param location the location to test
73+
* @return The result of {@link DataHandle#exists()} on a newly created handle
74+
* on this location
75+
* @throws IOException
76+
*/
77+
default boolean exists(final Location location) throws IOException {
78+
try (DataHandle<Location> handle = create(location)) {
79+
return handle.exists();
80+
}
81+
}
6682
}

0 commit comments

Comments
 (0)