Skip to content

Commit 63cf9dc

Browse files
committed
DataHandle: return length -1 when non-existent
This avoids a problem where asking a FileHandle for its length causes a previously non-existent file to be created.
1 parent f0a30f1 commit 63cf9dc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ default String checksum() throws IOException {
123123
*/
124124
void seek(long pos) throws IOException;
125125

126-
/** Returns the length of the data in bytes. */
126+
/**
127+
* Returns the length of the data in bytes.
128+
*
129+
* @return The length, or -1 if the length is unknown.
130+
*/
127131
long length() throws IOException;
128132

129133
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public long offset() throws IOException {
103103

104104
@Override
105105
public long length() throws IOException {
106-
return raf().length();
106+
return exists() ? raf().length() : -1;
107107
}
108108

109109
@Override

0 commit comments

Comments
 (0)