Skip to content

Commit

Permalink
Fix InputStream violation in DataBufferInputStream
Browse files Browse the repository at this point in the history
This commit fixes an issue in DataBufferInputStream::mark, which before
did not follow the contract defined by InputStream.

Closes gh-29642
  • Loading branch information
poutsma committed Dec 7, 2022
1 parent c79474d commit 92a6e7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -77,8 +77,9 @@ public boolean markSupported() {
}

@Override
public void mark(int mark) {
this.mark = mark;
public void mark(int readLimit) {
Assert.isTrue(readLimit > 0, "readLimit must be greater than 0");
this.mark = this.dataBuffer.readPosition();
}

@Override
Expand Down
Expand Up @@ -318,6 +318,9 @@ void inputStream(DataBufferFactory bufferFactory) throws Exception {
assertThat(result).isEqualTo((byte) 'b');
assertThat(inputStream.available()).isEqualTo(3);

assertThat(inputStream.markSupported()).isTrue();
inputStream.mark(2);

byte[] bytes = new byte[2];
int len = inputStream.read(bytes);
assertThat(len).isEqualTo(2);
Expand All @@ -333,6 +336,12 @@ void inputStream(DataBufferFactory bufferFactory) throws Exception {
assertThat(inputStream.read()).isEqualTo(-1);
assertThat(inputStream.read(bytes)).isEqualTo(-1);

inputStream.reset();
bytes = new byte[3];
len = inputStream.read(bytes);
assertThat(len).isEqualTo(3);
assertThat(bytes).containsExactly('c', 'd', 'e');

release(buffer);
}

Expand Down

0 comments on commit 92a6e7d

Please sign in to comment.