Browse Source

Merge pull request #29889 from xavier-b:main

* gh-29889:
  Use DataBuffer::toString instead of CharBuffer
pull/29903/head
Arjen Poutsma 3 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 @@
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;

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

@ -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);

Loading…
Cancel
Save