提交 dccc7814 编写于 作者: R Rossen Stoyanchev

Expose defaultCharset in StringDecoder

Closes gh-25762
上级 dde79a9b
......@@ -72,6 +72,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
private final boolean stripDelimiter;
private Charset defaultCharset = DEFAULT_CHARSET;
private final ConcurrentMap<Charset, byte[][]> delimitersCache = new ConcurrentHashMap<>();
......@@ -83,6 +85,24 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
}
/**
* Set the default character set to fall back on if the MimeType does not specify any.
* <p>By default this is {@code UTF-8}.
* @param defaultCharset the charset to fall back on
* @since 5.2.9
*/
public void setDefaultCharset(Charset defaultCharset) {
this.defaultCharset = defaultCharset;
}
/**
* Return the configured {@link #setDefaultCharset(Charset) defaultCharset}.
* @since 5.2.9
*/
public Charset getDefaultCharset() {
return this.defaultCharset;
}
@Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
return (elementType.resolve() == String.class && super.canDecode(elementType, mimeType));
......@@ -136,12 +156,12 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
return value;
}
private static Charset getCharset(@Nullable MimeType mimeType) {
private Charset getCharset(@Nullable MimeType mimeType) {
if (mimeType != null && mimeType.getCharset() != null) {
return mimeType.getCharset();
}
else {
return DEFAULT_CHARSET;
return getDefaultCharset();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册