-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed as not planned
Closed as not planned
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another
Description
When calculating the ContentLength
and writing data to the OutputStream
in StringHttpMessageConverter
, calling str.getBytes(charset)
repeatedly will result in unnecessary array objects occupying memory
Lines 103 to 106 in 09917fa
protected Long getContentLength(String str, @Nullable MediaType contentType) { | |
Charset charset = getContentTypeCharset(contentType); | |
return (long) str.getBytes(charset).length; | |
} |
Lines 122 to 129 in 09917fa
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException { | |
HttpHeaders headers = outputMessage.getHeaders(); | |
if (this.writeAcceptCharset && headers.get(HttpHeaders.ACCEPT_CHARSET) == null) { | |
headers.setAcceptCharset(getAcceptedCharsets()); | |
} | |
Charset charset = getContentTypeCharset(headers.getContentType()); | |
StreamUtils.copy(str, charset, outputMessage.getBody()); | |
} |
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another