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
5555 private final LRUReplacementStrategy replacementStrategy ;
5656 private final Map <Integer , Integer > pageToSlot ;
5757
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 ;
5864 private long offset = 0l ;
5965 private byte [] currentPage ;
6066 private int currentPageID = -1 ;
@@ -190,6 +196,12 @@ public void seek(final long pos) throws IOException {
190196 this .offset = pos ;
191197 }
192198
199+ @ Override
200+ public long length () throws IOException {
201+ if (length < 0 ) length = super .length ();
202+ return length ;
203+ }
204+
193205 @ Override
194206 public int read (final byte [] b , final int targetOffset , final int len )
195207 throws IOException
You can’t perform that action at this time.
0 commit comments