Skip to content

Commit 8779e52

Browse files
authored
implement mark() in class FilterStreamInput (opensearch-project#13098)
* implement mark() in class FilterStreamInput Signed-off-by: kkewwei <[email protected]> * implement markSupported() in class FilterStreamInput Signed-off-by: kkewwei <[email protected]> * add CHANGELOG Signed-off-by: kkewwei <[email protected]> --------- Signed-off-by: kkewwei <[email protected]>
1 parent 3aaada6 commit 8779e52

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4444
- Fix bulk API ignores ingest pipeline for upsert ([#12883](https://github.com/opensearch-project/OpenSearch/pull/12883))
4545
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
4646
- Fix UOE While building Exists query for nested search_as_you_type field ([#12048](https://github.com/opensearch-project/OpenSearch/pull/12048))
47-
- Client with Java 8 runtime and Apache HttpClient 5 Transport fails with java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer ([#13100](https://github.com/opensearch-project/opensearch-java/pull/13100))
47+
- Client with Java 8 runtime and Apache HttpClient 5 Transport fails with java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer ([#13100](https://github.com/opensearch-project/opensearch-java/pull/13100))
48+
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
4849

4950
### Security
5051

libs/core/src/main/java/org/opensearch/core/common/io/stream/FilterStreamInput.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public void reset() throws IOException {
8080
delegate.reset();
8181
}
8282

83+
@Override
84+
public void mark(int readlimit) {
85+
delegate.mark(readlimit);
86+
}
87+
88+
@Override
89+
public boolean markSupported() {
90+
return delegate.markSupported();
91+
}
92+
8393
@Override
8494
public int read() throws IOException {
8595
return delegate.read();

libs/core/src/test/java/org/opensearch/core/common/io/stream/FilterStreamInputTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.opensearch.core.common.bytes.BytesReference;
1313

1414
import java.io.IOException;
15+
import java.nio.ByteBuffer;
16+
17+
import static org.hamcrest.Matchers.is;
1518

1619
/** test the FilterStreamInput using the same BaseStreamTests */
1720
public class FilterStreamInputTests extends BaseStreamTests {
@@ -21,4 +24,24 @@ protected StreamInput getStreamInput(BytesReference bytesReference) throws IOExc
2124
return new FilterStreamInput(StreamInput.wrap(br.bytes, br.offset, br.length)) {
2225
};
2326
}
27+
28+
public void testMarkAndReset() throws IOException {
29+
FilterStreamInputTests filterStreamInputTests = new FilterStreamInputTests();
30+
31+
ByteBuffer buffer = ByteBuffer.wrap(new byte[20]);
32+
for (int i = 0; i < buffer.limit(); i++) {
33+
buffer.put((byte) i);
34+
}
35+
buffer.rewind();
36+
BytesReference bytesReference = BytesReference.fromByteBuffer(buffer);
37+
StreamInput streamInput = filterStreamInputTests.getStreamInput(bytesReference);
38+
streamInput.read();
39+
assertThat(streamInput.markSupported(), is(true));
40+
streamInput.mark(-1);
41+
int int1 = streamInput.read();
42+
int int2 = streamInput.read();
43+
streamInput.reset();
44+
assertEquals(int1, streamInput.read());
45+
assertEquals(int2, streamInput.read());
46+
}
2447
}

0 commit comments

Comments
 (0)