Skip to content

Commit c59b3b0

Browse files
committed
DataHandle: add exists() method
1 parent 5e90165 commit c59b3b0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public boolean isWritable() {
6363
return !bytes().isReadOnly();
6464
}
6565

66+
@Override
67+
public boolean exists() {
68+
return true;
69+
}
70+
6671
@Override
6772
public long offset() {
6873
return offset;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public enum ByteOrder {
7171
/** Gets whether writing to this handle is supported. */
7272
boolean isWritable();
7373

74+
/**
75+
* Tests whether this handle's location actually exists at the source.
76+
*
77+
* @return True if the location exists; false if not.
78+
* @throws IOException If something goes wrong with the existence check.
79+
*/
80+
boolean exists() throws IOException;
81+
7482
/** Returns the current offset in the stream. */
7583
long offset() throws IOException;
7684

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public boolean isWritable() {
6363
return true;
6464
}
6565

66+
@Override
67+
public boolean exists() {
68+
return true;
69+
}
70+
6671
@Override
6772
public long offset() {
6873
return offset;
@@ -133,5 +138,4 @@ public void close() {
133138
public Class<DummyLocation> getType() {
134139
return DummyLocation.class;
135140
}
136-
137141
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public boolean isWritable() {
8484
return getMode().contains("w");
8585
}
8686

87+
@Override
88+
public boolean exists() {
89+
return get().getFile().exists();
90+
}
91+
8792
@Override
8893
public long offset() throws IOException {
8994
return raf().getFilePointer();
@@ -299,5 +304,4 @@ private synchronized void initRAF() throws IOException {
299304
if (raf != null) return;
300305
raf = new RandomAccessFile(get().getFile(), getMode());
301306
}
302-
303307
}

0 commit comments

Comments
 (0)