Merge pull request #29889 from xavier-b:main

* gh-29889:
  Use DataBuffer::toString instead of CharBuffer
This commit is contained in:
Arjen Poutsma
2023-01-30 15:03:04 +01:00
2 changed files with 2 additions and 6 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.core.codec; package org.springframework.core.codec;
import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
@@ -189,9 +188,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Charset charset = getCharset(mimeType); Charset charset = getCharset(mimeType);
CharBuffer charBuffer = charset.decode(dataBuffer.toByteBuffer()); String value = dataBuffer.toString(charset);
DataBufferUtils.release(dataBuffer); DataBufferUtils.release(dataBuffer);
String value = charBuffer.toString();
LogFormatUtils.traceDebug(logger, traceOn -> { LogFormatUtils.traceDebug(logger, traceOn -> {
String formatted = LogFormatUtils.formatValue(value, !traceOn); String formatted = LogFormatUtils.formatValue(value, !traceOn);
return Hints.getLogPrefix(hints) + "Decoded " + formatted; return Hints.getLogPrefix(hints) + "Decoded " + formatted;

View File

@@ -17,7 +17,6 @@
package org.springframework.http.codec; package org.springframework.http.codec;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
@@ -129,8 +128,7 @@ public class FormHttpMessageReader extends LoggingCodecSupport
return DataBufferUtils.join(message.getBody(), this.maxInMemorySize) return DataBufferUtils.join(message.getBody(), this.maxInMemorySize)
.map(buffer -> { .map(buffer -> {
CharBuffer charBuffer = charset.decode(buffer.toByteBuffer()); String body = buffer.toString(charset);
String body = charBuffer.toString();
DataBufferUtils.release(buffer); DataBufferUtils.release(buffer);
MultiValueMap<String, String> formData = parseFormData(charset, body); MultiValueMap<String, String> formData = parseFormData(charset, body);
logFormData(formData, hints); logFormData(formData, hints);