Skip to content

Commit

Permalink
implement mark() in class FilterStreamInput
Browse files Browse the repository at this point in the history
Signed-off-by: kkewwei <kkewwei@163.com>
  • Loading branch information
kkewwei committed Apr 5, 2024
1 parent 19d6c5c commit bea846c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public void reset() throws IOException {
delegate.reset();
}

@Override
public void mark(int readlimit) {
delegate.mark(readlimit);
}

@Override
public int read() throws IOException {
return delegate.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
package org.opensearch.core.common.io.stream;

import org.apache.lucene.util.BytesRef;
import org.junit.Test;
import org.opensearch.core.common.bytes.BytesReference;

import java.io.IOException;
import java.nio.ByteBuffer;

/** test the FilterStreamInput using the same BaseStreamTests */
public class FilterStreamInputTests extends BaseStreamTests {
Expand All @@ -21,4 +23,23 @@ protected StreamInput getStreamInput(BytesReference bytesReference) throws IOExc
return new FilterStreamInput(StreamInput.wrap(br.bytes, br.offset, br.length)) {
};
}

public void testMarkAndReset() throws IOException {
FilterStreamInputTests filterStreamInputTests = new FilterStreamInputTests();

ByteBuffer buffer = ByteBuffer.wrap(new byte[20]);
for (int i = 0; i < buffer.limit(); i++) {
buffer.put((byte) i);
}
buffer.rewind();
BytesReference bytesReference = BytesReference.fromByteBuffer(buffer);
StreamInput streamInput = filterStreamInputTests.getStreamInput(bytesReference);
streamInput.read();
streamInput.mark(-1);
int int1 = streamInput.read();
int int2 = streamInput.read();
streamInput.reset();
assertEquals(int1, streamInput.read());
assertEquals(int2, streamInput.read());
}
}

0 comments on commit bea846c

Please sign in to comment.