diff --git a/src/main/java/loci/common/URLHandle.java b/src/main/java/loci/common/URLHandle.java index 96762cf2..47a46b08 100644 --- a/src/main/java/loci/common/URLHandle.java +++ b/src/main/java/loci/common/URLHandle.java @@ -80,9 +80,19 @@ public URLHandle(String url) throws IOException { @Override public void seek(long pos) throws IOException { if (pos < fp && pos >= mark) { - stream.reset(); - fp = mark; - skip(pos - fp); + try { + // try to reset to the marked position first + // if it works, this is faster + stream.reset(); + fp = mark; + skip(pos - fp); + } + catch (IOException e) { + // if resetting to the mark fails for whatever reason, + // just reset the whole stream and seek from the beginning + // this is slower but more likely to work + super.seek(pos); + } } else super.seek(pos); }