Merge branch '4.1.x'

Closes gh-51521
This commit is contained in:
Andy Wilkinson
2026-09-01 16:12:22 +01:00
2 changed files with 10 additions and 2 deletions
@@ -85,7 +85,7 @@ class NestedByteChannel implements SeekableByteChannel {
while (dst.remaining() > 0) {
int count = this.resources.getData().read(dst, this.position);
if (count <= 0) {
return (total != 0) ? 0 : count;
return (total != 0) ? total : count;
}
total += count;
this.position += count;
@@ -118,11 +118,19 @@ class NestedByteChannelTests {
void readReadsBytesAndIncrementsPosition() throws IOException {
ByteBuffer dst = ByteBuffer.allocate(10);
assertThat(this.channel.position()).isZero();
this.channel.read(dst);
assertThat(this.channel.read(dst)).isEqualTo(10);
assertThat(this.channel.position()).isEqualTo(10L);
assertThat(dst.array()).isNotEqualTo(ByteBuffer.allocate(10).array());
}
@Test
void whenDataCannotFillBufferReadReturnsBytesRead() throws IOException {
ByteBuffer dst = ByteBuffer.allocate(8192);
assertThat(this.channel.position()).isZero();
assertThat(this.channel.read(dst)).isEqualTo(638);
assertThat(this.channel.position()).isEqualTo(638L);
}
@Test // gh-38592
void readReadsAsManyBytesAsPossible() throws Exception {
// ZipFileSystem checks that the number of bytes read matches an expected value