Browse Source

Merge pull request #29889 from xavier-b:main

* gh-29889:
  Use DataBuffer::toString instead of CharBuffer
pull/29903/head
Arjen Poutsma 2 years ago
parent
commit
c13dfc5144
  1. 4
      spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
  2. 4
      spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java

4
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

@ -16,7 +16,6 @@ @@ -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> { @@ -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;

4
spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java

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

Loading…
Cancel
Save