mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-09 19:09:03 +00:00
Fix zero-length byte buffer in InspectedContent
See gh-48649 Signed-off-by: 高春晖 <18220699480@163.com>
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
+7
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user