File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
src/main/java/org/scijava/io/handle Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ public class ReadBufferDataHandle<L extends Location> extends AbstractHigherOrde
55
55
private final LRUReplacementStrategy replacementStrategy ;
56
56
private final Map <Integer , Integer > pageToSlot ;
57
57
58
+ /**
59
+ * Cached length value, for performance. When reading data, length is not
60
+ * expected to change, but querying it (e.g. via native filesystem access)
61
+ * can be slow, and we need to query the length frequently.
62
+ */
63
+ private long length = -1 ;
58
64
private long offset = 0l ;
59
65
private byte [] currentPage ;
60
66
private int currentPageID = -1 ;
@@ -190,6 +196,12 @@ public void seek(final long pos) throws IOException {
190
196
this .offset = pos ;
191
197
}
192
198
199
+ @ Override
200
+ public long length () throws IOException {
201
+ if (length < 0 ) length = super .length ();
202
+ return length ;
203
+ }
204
+
193
205
@ Override
194
206
public int read (final byte [] b , final int targetOffset , final int len )
195
207
throws IOException
You can’t perform that action at this time.
0 commit comments