Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public void reset() throws IOException {
if (markedSlice < 0 || markedSliceOffset < 0) {
throw new IOException("Mark has not been set");
}
if (initialized && nextSlice == markedSlice + 1 && currentSliceOffset == markedSliceOffset) {
// Reset at the marked offset should return immediately without re-opening the slice
return;
}

nextSlice = markedSlice;
initialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ protected InputStream openSlice(int slice) throws IOException {

// Mark
input.mark(randomNonNegativeInt());
int slicesOpenedAtMark = streamsOpened.size();

// Read or skip up to another random point
final int moreBytes = randomIntBetween(0, bytes.length - mark);
int moreBytes = randomIntBetween(0, bytes.length - mark);
if (moreBytes > 0) {
if (randomBoolean()) {
final var moreBytesRead = new byte[moreBytes];
Expand All @@ -171,11 +172,13 @@ protected InputStream openSlice(int slice) throws IOException {

// Randomly read to EOF
if (randomBoolean()) {
input.readAllBytes();
moreBytes += input.readAllBytes().length;
}

// Reset
input.reset();
int slicesOpenedAfterReset = streamsOpened.size();
assert moreBytes > 0 || mark == 0 || slicesOpenedAfterReset == slicesOpenedAtMark : "Reset at mark should not re-open slices";

// Read all remaining bytes, which should be the bytes from mark up to the end
final int remainingBytes = bytes.length - mark;
Expand Down