Fix InputStream violation in DataBufferInputStream

This commit fixes an issue in DataBufferInputStream::mark, which before
did not follow the contract defined by InputStream.

Closes gh-29642
This commit is contained in:
Arjen Poutsma 2022-12-07 15:23:19 +01:00
parent c79474d269
commit 92a6e7ddcd
2 changed files with 12 additions and 2 deletions

View File

@ -77,8 +77,9 @@ final class DataBufferInputStream extends InputStream {
}
@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

View File

@ -318,6 +318,9 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
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);
@ -333,6 +336,12 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
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);
}