diff --git a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java index 5a408d8749..8b8793e277 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java @@ -93,11 +93,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); - long length = inputMessage.getHeaders().getContentLength(); - byte[] bytes = (length >= 0 && length <= Integer.MAX_VALUE ? - inputMessage.getBody().readNBytes((int) length) : - inputMessage.getBody().readAllBytes()); - return new String(bytes, charset); + return StreamUtils.copyToString(inputMessage.getBody(), charset); } @Override