parent
df1f8139cc
commit
c56c16d7ba
|
@ -51,16 +51,10 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
long contentLength = inputMessage.getHeaders().getContentLength();
|
||||
final int len;
|
||||
if (contentLength >= 0 && contentLength <= Integer.MAX_VALUE) {
|
||||
len = (int) contentLength;
|
||||
}
|
||||
else {
|
||||
len = Integer.MAX_VALUE;
|
||||
}
|
||||
return inputMessage.getBody().readNBytes(len);
|
||||
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage message) throws IOException {
|
||||
long length = message.getHeaders().getContentLength();
|
||||
return (length >= 0 && length < Integer.MAX_VALUE ?
|
||||
message.getBody().readNBytes((int) length) : message.getBody().readAllBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -32,11 +32,13 @@ public class ByteArrayHttpMessageConverterTests {
|
|||
|
||||
private ByteArrayHttpMessageConverter converter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
converter = new ByteArrayHttpMessageConverter();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void canRead() {
|
||||
assertThat(converter.canRead(byte[].class, new MediaType("application", "octet-stream"))).isTrue();
|
||||
|
@ -73,10 +75,8 @@ public class ByteArrayHttpMessageConverterTests {
|
|||
byte[] body = new byte[]{0x1, 0x2};
|
||||
converter.write(body, null, outputMessage);
|
||||
assertThat(outputMessage.getBodyAsBytes()).as("Invalid result").isEqualTo(body);
|
||||
assertThat(outputMessage.getHeaders().getContentType())
|
||||
.as("Invalid content-type").isEqualTo(MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertThat(outputMessage.getHeaders().getContentLength())
|
||||
.as("Invalid content-length").isEqualTo(2);
|
||||
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertThat(outputMessage.getHeaders().getContentLength()).isEqualTo(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue