Fix zero-length byte buffer in InspectedContent

See gh-48649

Signed-off-by: 高春晖 <18220699480@163.com>
This commit is contained in:
高春晖
2025-12-31 10:39:38 +01:00
committed by Stéphane Nicoll
parent 1a4ad9595e
commit ba94cc48f2
2 changed files with 8 additions and 1 deletions
@@ -139,7 +139,7 @@ public class InspectedContent implements Content {
private File tempFile;
private final byte[] singleByteBuffer = new byte[0];
private final byte[] singleByteBuffer = new byte[1];
private InspectingOutputStream(Inspector[] inspectors) {
this.inspectors = inspectors;
@@ -90,6 +90,13 @@ class InspectedContentTests {
0xa3, 0xbf, 0x4f, 0x1b, 0x2b, 0x0b, 0x82, 0x2c, 0xd1, 0x5d, 0x6c, 0x15, 0xb0, 0xf0, 0x0a, 0x08);
}
@Test
void ofWritingSingleByteShouldWork() throws Exception {
InspectedContent content = InspectedContent.of((outputStream) -> outputStream.write('A'));
assertThat(content.size()).isEqualTo(1);
assertThat(readBytes(content)).containsExactly('A');
}
private byte[] readBytes(InspectedContent content) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
content.writeTo(outputStream);