Skip to content

Commit

Permalink
Merge pull request #82 from melissalinkert/url-reset
Browse files Browse the repository at this point in the history
URLHandle: fall back to resetting stream if resetting to a mark fails
  • Loading branch information
dgault authored Oct 6, 2023
2 parents fb78eb4 + a67aca0 commit 4776bca
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/loci/common/URLHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4776bca

Please sign in to comment.