Merge pull request #11036 from dreis2211:standard-charsets-polishing
* pr/11036: Use StandardCharsets where possible
This commit is contained in:
commit
2de0247ce9
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.context;
|
package org.springframework.boot.autoconfigure.context;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties for Message Source.
|
* Configuration properties for Message Source.
|
||||||
|
|
@ -37,7 +38,7 @@ public class MessageSourceProperties {
|
||||||
/**
|
/**
|
||||||
* Message bundles encoding.
|
* Message bundles encoding.
|
||||||
*/
|
*/
|
||||||
private Charset encoding = Charset.forName("UTF-8");
|
private Charset encoding = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles
|
* Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.http;
|
package org.springframework.boot.autoconfigure.http;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -32,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@ConfigurationProperties(prefix = "spring.http.encoding")
|
@ConfigurationProperties(prefix = "spring.http.encoding")
|
||||||
public class HttpEncodingProperties {
|
public class HttpEncodingProperties {
|
||||||
|
|
||||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Charset of HTTP requests and responses. Added to the "Content-Type" header if not
|
* Charset of HTTP requests and responses. Added to the "Content-Type" header if not
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.mail;
|
package org.springframework.boot.autoconfigure.mail;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@ConfigurationProperties(prefix = "spring.mail")
|
@ConfigurationProperties(prefix = "spring.mail")
|
||||||
public class MailProperties {
|
public class MailProperties {
|
||||||
|
|
||||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP server host.
|
* SMTP server host.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.template;
|
package org.springframework.boot.autoconfigure.template;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ public abstract class AbstractViewResolverProperties {
|
||||||
|
|
||||||
private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
|
private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
|
||||||
|
|
||||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable MVC view resolution for this technology.
|
* Enable MVC view resolution for this technology.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.thymeleaf;
|
package org.springframework.boot.autoconfigure.thymeleaf;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
@ -34,7 +35,7 @@ import org.springframework.util.MimeType;
|
||||||
@ConfigurationProperties(prefix = "spring.thymeleaf")
|
@ConfigurationProperties(prefix = "spring.thymeleaf")
|
||||||
public class ThymeleafProperties {
|
public class ThymeleafProperties {
|
||||||
|
|
||||||
private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
|
private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public static final String DEFAULT_PREFIX = "classpath:/templates/";
|
public static final String DEFAULT_PREFIX = "classpath:/templates/";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.template;
|
package org.springframework.boot.autoconfigure.template;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class ViewResolverPropertiesTests {
|
||||||
@Test
|
@Test
|
||||||
public void defaultContentTypeCustomCharset() {
|
public void defaultContentTypeCustomCharset() {
|
||||||
ViewResolverProperties properties = new ViewResolverProperties();
|
ViewResolverProperties properties = new ViewResolverProperties();
|
||||||
properties.setCharset(Charset.forName("UTF-16"));
|
properties.setCharset(StandardCharsets.UTF_16);
|
||||||
assertThat(properties.getContentType()).hasToString("text/html;charset=UTF-16");
|
assertThat(properties.getContentType()).hasToString("text/html;charset=UTF-16");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ public class ViewResolverPropertiesTests {
|
||||||
public void customContentTypeCustomCharset() {
|
public void customContentTypeCustomCharset() {
|
||||||
ViewResolverProperties properties = new ViewResolverProperties();
|
ViewResolverProperties properties = new ViewResolverProperties();
|
||||||
properties.setContentType(MimeTypeUtils.parseMimeType("text/plain"));
|
properties.setContentType(MimeTypeUtils.parseMimeType("text/plain"));
|
||||||
properties.setCharset(Charset.forName("UTF-16"));
|
properties.setCharset(StandardCharsets.UTF_16);
|
||||||
assertThat(properties.getContentType()).hasToString("text/plain;charset=UTF-16");
|
assertThat(properties.getContentType()).hasToString("text/plain;charset=UTF-16");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class ViewResolverPropertiesTests {
|
||||||
public void customContentTypeWithPropertyAndCustomCharset() {
|
public void customContentTypeWithPropertyAndCustomCharset() {
|
||||||
ViewResolverProperties properties = new ViewResolverProperties();
|
ViewResolverProperties properties = new ViewResolverProperties();
|
||||||
properties.setContentType(MimeTypeUtils.parseMimeType("text/plain;foo=bar"));
|
properties.setContentType(MimeTypeUtils.parseMimeType("text/plain;foo=bar"));
|
||||||
properties.setCharset(Charset.forName("UTF-16"));
|
properties.setCharset(StandardCharsets.UTF_16);
|
||||||
assertThat(properties.getContentType())
|
assertThat(properties.getContentType())
|
||||||
.hasToString("text/plain;charset=UTF-16;foo=bar");
|
.hasToString("text/plain;charset=UTF-16;foo=bar");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||||
Map<String, Object> values = new HashMap<>();
|
Map<String, Object> values = new HashMap<>();
|
||||||
values.put("Boolean.TRUE", true);
|
values.put("Boolean.TRUE", true);
|
||||||
values.put("Boolean.FALSE", false);
|
values.put("Boolean.FALSE", false);
|
||||||
|
values.put("StandardCharsets.ISO_8859_1", "ISO-8859-1");
|
||||||
|
values.put("StandardCharsets.UTF_8", "UTF-8");
|
||||||
|
values.put("StandardCharsets.UTF_16", "UTF-16");
|
||||||
|
values.put("StandardCharsets.US_ASCII", "US-ASCII");
|
||||||
wellKnownStaticFinals = Collections.unmodifiableMap(values);
|
wellKnownStaticFinals = Collections.unmodifiableMap(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.configurationsample.fieldvalues;
|
package org.springframework.boot.configurationsample.fieldvalues;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
|
|
@ -41,7 +42,7 @@ public class FieldValues {
|
||||||
|
|
||||||
private static final Integer INTEGER_OBJ_CONST = 4;
|
private static final Integer INTEGER_OBJ_CONST = 4;
|
||||||
|
|
||||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
private static final MimeType DEFAULT_MIME_TYPE = MimeType.valueOf("text/plain");
|
private static final MimeType DEFAULT_MIME_TYPE = MimeType.valueOf("text/plain");
|
||||||
|
|
||||||
|
|
@ -77,7 +78,7 @@ public class FieldValues {
|
||||||
|
|
||||||
private Integer integerObjectConst = INTEGER_OBJ_CONST;
|
private Integer integerObjectConst = INTEGER_OBJ_CONST;
|
||||||
|
|
||||||
private Charset charset = Charset.forName("US-ASCII");
|
private Charset charset = StandardCharsets.US_ASCII;
|
||||||
|
|
||||||
private Charset charsetConst = DEFAULT_CHARSET;
|
private Charset charsetConst = DEFAULT_CHARSET;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue