From 23162bb3060bc4166bbed8f2452e9abe44a3b3ca Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Fri, 29 Sep 2023 17:15:23 +0100 Subject: [PATCH] Undo optimization from 12fe2c that can cause regression Closes gh-31327 --- .../http/converter/StringHttpMessageConverter.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 5a408d874976..8b8793e277eb 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 boolean supports(Class clazz) { @Override protected String readInternal(Class 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