Use DataBuffer::toString instead of CharBuffer
This commit ensures that converting DataBuffers to a String does not use an expensive ByteBuffer allocation. Closes gh-29889
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@@ -189,9 +188,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
Charset charset = getCharset(mimeType);
|
||||
CharBuffer charBuffer = charset.decode(dataBuffer.toByteBuffer());
|
||||
String value = dataBuffer.toString(charset);
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
String value = charBuffer.toString();
|
||||
LogFormatUtils.traceDebug(logger, traceOn -> {
|
||||
String formatted = LogFormatUtils.formatValue(value, !traceOn);
|
||||
return Hints.getLogPrefix(hints) + "Decoded " + formatted;
|
||||
|
||||
Reference in New Issue
Block a user