Utilize StandardCharsets
Closes gh-10972
This commit is contained in:
committed by
Stephane Nicoll
parent
e9c81bf702
commit
bd0dcfb172
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class Token {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private final String encoded;
|
||||
|
||||
private final String signature;
|
||||
@@ -63,7 +61,7 @@ public class Token {
|
||||
private Map<String, Object> parseJson(String base64) {
|
||||
try {
|
||||
byte[] bytes = Base64Utils.decodeFromUrlSafeString(base64);
|
||||
return JsonParserFactory.getJsonParser().parseMap(new String(bytes, UTF_8));
|
||||
return JsonParserFactory.getJsonParser().parseMap(new String(bytes, StandardCharsets.UTF_8));
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN,
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
@@ -54,8 +54,6 @@ public class ReactiveTokenValidatorTests {
|
||||
|
||||
private static final byte[] DOT = ".".getBytes();
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
@Mock
|
||||
private ReactiveCloudFoundrySecurityService securityService;
|
||||
|
||||
@@ -226,7 +224,7 @@ public class ReactiveTokenValidatorTests {
|
||||
byte[] crypto = signature.sign();
|
||||
byte[] token = dotConcat(Base64Utils.encodeUrlSafe(header),
|
||||
Base64Utils.encodeUrlSafe(claims), Base64Utils.encodeUrlSafe(crypto));
|
||||
return new String(token, UTF_8);
|
||||
return new String(token, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private PrivateKey getPrivateKey()
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
@@ -56,8 +56,6 @@ public class TokenValidatorTests {
|
||||
|
||||
private static final byte[] DOT = ".".getBytes();
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -216,7 +214,7 @@ public class TokenValidatorTests {
|
||||
byte[] crypto = signature.sign();
|
||||
byte[] token = dotConcat(Base64Utils.encodeUrlSafe(header),
|
||||
Base64Utils.encodeUrlSafe(claims), Base64Utils.encodeUrlSafe(crypto));
|
||||
return new String(token, UTF_8);
|
||||
return new String(token, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private PrivateKey getPrivateKey()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jersey;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
@@ -105,7 +105,7 @@ public class JerseyAutoConfigurationServletContainerTests {
|
||||
jerseyServlet.setServlet(new ServletContainer());
|
||||
jerseyServlet.setOverridable(false);
|
||||
context.addChild(jerseyServlet);
|
||||
String pattern = UDecoder.URLDecode("/*", Charset.forName("UTF-8"));
|
||||
String pattern = UDecoder.URLDecode("/*", StandardCharsets.UTF_8);
|
||||
context.addServletMappingDecoded(pattern, servletName);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure.web;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -141,7 +141,7 @@ public class ServerPropertiesTests {
|
||||
public void testCustomizeUriEncoding() throws Exception {
|
||||
bind("server.tomcat.uri-encoding", "US-ASCII");
|
||||
assertThat(this.properties.getTomcat().getUriEncoding())
|
||||
.isEqualTo(Charset.forName("US-ASCII"));
|
||||
.isEqualTo(StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.servlet;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -160,10 +160,10 @@ public class HttpEncodingAutoConfigurationTests {
|
||||
.getLocaleCharsetMappings().size()).isEqualTo(2);
|
||||
assertThat(this.context.getBean(MockServletWebServerFactory.class)
|
||||
.getLocaleCharsetMappings().get(Locale.ENGLISH))
|
||||
.isEqualTo(Charset.forName("UTF-8"));
|
||||
.isEqualTo(StandardCharsets.UTF_8);
|
||||
assertThat(this.context.getBean(MockServletWebServerFactory.class)
|
||||
.getLocaleCharsetMappings().get(Locale.FRANCE))
|
||||
.isEqualTo(Charset.forName("UTF-8"));
|
||||
.isEqualTo(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.cli.command.init;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
@@ -47,8 +48,6 @@ class InitializrService {
|
||||
|
||||
private static final String FILENAME_HEADER_PREFIX = "filename=\"";
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
/**
|
||||
* Accept header to use to retrieve the json meta-data.
|
||||
*/
|
||||
@@ -241,7 +240,7 @@ class InitializrService {
|
||||
private String getContent(HttpEntity entity) throws IOException {
|
||||
ContentType contentType = ContentType.getOrDefault(entity);
|
||||
Charset charset = contentType.getCharset();
|
||||
charset = (charset != null ? charset : UTF_8);
|
||||
charset = (charset != null ? charset : StandardCharsets.UTF_8);
|
||||
byte[] content = FileCopyUtils.copyToByteArray(entity.getContent());
|
||||
return new String(content, charset);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -70,7 +71,7 @@ class GroovyGrabDependencyResolver implements DependencyResolver {
|
||||
File file = File.createTempFile("SpringCLIDependency", ".groovy");
|
||||
file.deleteOnExit();
|
||||
try (OutputStreamWriter stream = new OutputStreamWriter(
|
||||
new FileOutputStream(file), "UTF-8")) {
|
||||
new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||
for (String artifactIdentifier : artifactIdentifiers) {
|
||||
stream.write("@Grab('" + artifactIdentifier + "')");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.cli.command.init;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.StreamUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InitializrServiceMetadata}
|
||||
* Tests for {@link InitializrServiceMetadata}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -94,7 +94,7 @@ public class InitializrServiceMetadataTests {
|
||||
"metadata/service-metadata-" + version + ".json");
|
||||
try (InputStream stream = resource.getInputStream()) {
|
||||
return new JSONObject(
|
||||
StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
|
||||
StreamUtils.copyToString(stream, StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.cli.command.init;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.StreamUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProjectGenerationRequest}
|
||||
* Tests for {@link ProjectGenerationRequest}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Eddú Meléndez
|
||||
@@ -253,7 +253,7 @@ public class ProjectGenerationRequestTests {
|
||||
Resource resource = new ClassPathResource(
|
||||
"metadata/service-metadata-" + version + ".json");
|
||||
String content = StreamUtils.copyToString(resource.getInputStream(),
|
||||
Charset.forName("UTF-8"));
|
||||
StandardCharsets.UTF_8);
|
||||
JSONObject json = new JSONObject(content);
|
||||
return new InitializrServiceMetadata(json);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
@@ -54,8 +54,6 @@ public class RestartClassLoaderTests {
|
||||
|
||||
private static final String PACKAGE_PATH = PACKAGE.replace('.', '/');
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -89,7 +87,7 @@ public class RestartClassLoaderTests {
|
||||
StreamUtils.copy(getClass().getResourceAsStream("Sample.class"), jarOutputStream);
|
||||
jarOutputStream.closeEntry();
|
||||
jarOutputStream.putNextEntry(new ZipEntry(PACKAGE_PATH + "/Sample.txt"));
|
||||
StreamUtils.copy("fromchild", UTF_8, jarOutputStream);
|
||||
StreamUtils.copy("fromchild", StandardCharsets.UTF_8, jarOutputStream);
|
||||
jarOutputStream.closeEntry();
|
||||
jarOutputStream.close();
|
||||
return file;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -57,7 +58,7 @@ public class DataRedisTestIntegrationTests {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private static final Charset CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
@Test
|
||||
public void testRepository() {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.test.autoconfigure.data.redis;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class ExampleService {
|
||||
|
||||
private static final Charset CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
private RedisOperations<Object, Object> operations;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -42,7 +43,7 @@ class JsonLoader {
|
||||
|
||||
JsonLoader(Class<?> resourceLoadClass, Charset charset) {
|
||||
this.resourceLoadClass = resourceLoadClass;
|
||||
this.charset = charset == null ? Charset.forName("UTF-8") : charset;
|
||||
this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
|
||||
}
|
||||
|
||||
Class<?> getResourceLoadClass() {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.configurationmetadata;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,12 +33,7 @@ import java.util.Map;
|
||||
*/
|
||||
public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
|
||||
/**
|
||||
* UTF-8 Charset.
|
||||
*/
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private Charset defaultCharset = UTF_8;
|
||||
private Charset defaultCharset = StandardCharsets.UTF_8;
|
||||
|
||||
private final JsonReader reader = new JsonReader();
|
||||
|
||||
@@ -159,7 +155,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using {@link #UTF_8} as the default charset and the
|
||||
* Create a new builder instance using {@link StandardCharsets#UTF_8} as the default charset and the
|
||||
* specified json resource.
|
||||
* @param inputStreams the source input streams
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
@@ -175,11 +171,11 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using {@link #UTF_8} as the default charset.
|
||||
* Create a new builder instance using {@link StandardCharsets#UTF_8} as the default charset.
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create() {
|
||||
return create(UTF_8);
|
||||
return create(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
@@ -27,13 +28,13 @@ import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonReader}
|
||||
* Tests for {@link JsonReader}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
private final JsonReader reader = new JsonReader();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -41,8 +41,6 @@ import org.springframework.boot.configurationprocessor.metadata.ItemMetadata.Ite
|
||||
*/
|
||||
public class JsonMarshaller {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private static final int BUFFER_SIZE = 4098;
|
||||
|
||||
public void write(ConfigurationMetadata metadata, OutputStream outputStream)
|
||||
@@ -53,7 +51,7 @@ public class JsonMarshaller {
|
||||
object.put("groups", converter.toJsonArray(metadata, ItemType.GROUP));
|
||||
object.put("properties", converter.toJsonArray(metadata, ItemType.PROPERTY));
|
||||
object.put("hints", converter.toJsonArray(metadata.getHints()));
|
||||
outputStream.write(object.toString(2).getBytes(UTF_8));
|
||||
outputStream.write(object.toString(2).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof IOException) {
|
||||
@@ -170,7 +168,7 @@ public class JsonMarshaller {
|
||||
|
||||
private String toString(InputStream inputStream) throws IOException {
|
||||
StringBuilder out = new StringBuilder();
|
||||
InputStreamReader reader = new InputStreamReader(inputStream, UTF_8);
|
||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
char[] buffer = new char[BUFFER_SIZE];
|
||||
int bytesRead;
|
||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -42,8 +42,6 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class DefaultLaunchScript implements LaunchScript {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
private static final Pattern PLACEHOLDER_PATTERN = Pattern
|
||||
@@ -76,7 +74,7 @@ public class DefaultLaunchScript implements LaunchScript {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
copy(inputStream, outputStream);
|
||||
return new String(outputStream.toByteArray(), UTF_8);
|
||||
return new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
@@ -129,7 +127,7 @@ public class DefaultLaunchScript implements LaunchScript {
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
return this.content.getBytes(UTF_8);
|
||||
return this.content.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader.jar;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Simple wrapper around a byte array that represents an ASCII. Used for performance
|
||||
@@ -27,8 +27,6 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
final class AsciiBytes {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
private final int offset;
|
||||
@@ -44,7 +42,7 @@ final class AsciiBytes {
|
||||
* @param string the source string
|
||||
*/
|
||||
AsciiBytes(String string) {
|
||||
this(string.getBytes(UTF_8));
|
||||
this(string.getBytes(StandardCharsets.UTF_8));
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@@ -124,7 +122,7 @@ final class AsciiBytes {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return append(string.getBytes(UTF_8));
|
||||
return append(string.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public AsciiBytes append(AsciiBytes asciiBytes) {
|
||||
@@ -147,7 +145,7 @@ final class AsciiBytes {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.string == null) {
|
||||
this.string = new String(this.bytes, this.offset, this.length, UTF_8);
|
||||
this.string = new String(this.bytes, this.offset, this.length, StandardCharsets.UTF_8);
|
||||
}
|
||||
return this.string;
|
||||
}
|
||||
@@ -215,7 +213,7 @@ final class AsciiBytes {
|
||||
}
|
||||
|
||||
static String toString(byte[] bytes) {
|
||||
return new String(bytes, UTF_8);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static int hashCode(String string) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -62,7 +63,7 @@ public class ResourceBanner implements Banner {
|
||||
try {
|
||||
String banner = StreamUtils.copyToString(this.resource.getInputStream(),
|
||||
environment.getProperty("banner.charset", Charset.class,
|
||||
Charset.forName("UTF-8")));
|
||||
StandardCharsets.UTF_8));
|
||||
|
||||
for (PropertyResolver resolver : getPropertyResolvers(environment,
|
||||
sourceClass)) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -155,7 +156,7 @@ class OriginTrackedPropertiesLoader {
|
||||
|
||||
CharacterReader(Resource resource) throws IOException {
|
||||
this.reader = new LineNumberReader(
|
||||
new InputStreamReader(resource.getInputStream(), "8859_1"));
|
||||
new InputStreamReader(resource.getInputStream(), StandardCharsets.ISO_8859_1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.boot.logging.logback;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
||||
@@ -60,8 +60,6 @@ class DefaultLogbackConfiguration {
|
||||
|
||||
private static final String MAX_FILE_SIZE = "10MB";
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private final PropertyResolver patterns;
|
||||
|
||||
private final LogFile logFile;
|
||||
@@ -125,7 +123,7 @@ class DefaultLogbackConfiguration {
|
||||
String logPattern = this.patterns.getProperty("logging.pattern.console",
|
||||
CONSOLE_LOG_PATTERN);
|
||||
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
|
||||
encoder.setCharset(UTF8);
|
||||
encoder.setCharset(StandardCharsets.UTF_8);
|
||||
config.start(encoder);
|
||||
appender.setEncoder(encoder);
|
||||
config.appender("CONSOLE", appender);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -97,7 +98,7 @@ import org.springframework.util.StringUtils;
|
||||
public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory
|
||||
implements ResourceLoaderAware {
|
||||
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
private static final Set<Class<?>> NO_CLASSES = Collections.emptySet();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.web.embedded.tomcat;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -248,7 +249,7 @@ public class TomcatServletWebServerFactoryTests
|
||||
@Test
|
||||
public void uriEncoding() throws Exception {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
factory.setUriEncoding(Charset.forName("US-ASCII"));
|
||||
factory.setUriEncoding(StandardCharsets.US_ASCII);
|
||||
Tomcat tomcat = getTomcat(factory);
|
||||
Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors()
|
||||
.get(tomcat.getService())[0];
|
||||
@@ -364,8 +365,8 @@ public class TomcatServletWebServerFactoryTests
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
this.webServer = factory.getWebServer();
|
||||
// override defaults, see org.apache.catalina.util.CharsetMapperDefault.properties
|
||||
assertThat(getCharset(Locale.ENGLISH).toString()).isEqualTo("UTF-8");
|
||||
assertThat(getCharset(Locale.FRENCH).toString()).isEqualTo("UTF-8");
|
||||
assertThat(getCharset(Locale.ENGLISH)).isEqualTo(StandardCharsets.UTF_8);
|
||||
assertThat(getCharset(Locale.FRENCH)).isEqualTo(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.boot.web.servlet.context;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
@@ -103,7 +103,7 @@ public class ServletWebServerMvcIntegrationTests {
|
||||
HttpMethod.GET);
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
String actual = StreamUtils.copyToString(response.getBody(),
|
||||
Charset.forName("UTF-8"));
|
||||
StandardCharsets.UTF_8);
|
||||
assertThat(actual).isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -911,10 +912,10 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
public void localeCharsetMappingsAreConfigured() throws Exception {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
Map<Locale, Charset> mappings = new HashMap<>();
|
||||
mappings.put(Locale.GERMAN, Charset.forName("UTF-8"));
|
||||
mappings.put(Locale.GERMAN, StandardCharsets.UTF_8);
|
||||
factory.setLocaleCharsetMappings(mappings);
|
||||
this.webServer = factory.getWebServer();
|
||||
assertThat(getCharset(Locale.GERMAN).toString()).isEqualTo("UTF-8");
|
||||
assertThat(getCharset(Locale.GERMAN)).isEqualTo(StandardCharsets.UTF_8);
|
||||
assertThat(getCharset(Locale.ITALIAN)).isNull();
|
||||
}
|
||||
|
||||
@@ -1063,7 +1064,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
protected String getResponse(String url, HttpMethod method, String... headers)
|
||||
throws IOException, URISyntaxException {
|
||||
try (ClientHttpResponse response = getClientResponse(url, method, headers)) {
|
||||
return StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
|
||||
return StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1078,7 +1079,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
throws IOException, URISyntaxException {
|
||||
try (ClientHttpResponse response = getClientResponse(url, method, requestFactory,
|
||||
headers)) {
|
||||
return StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
|
||||
return StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package sample.jetty;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -69,7 +69,7 @@ public class SampleJettyApplicationTests {
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
try (GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()))) {
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package sample.tomcat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.apache.coyote.AbstractProtocol;
|
||||
@@ -77,7 +78,7 @@ public class SampleTomcatApplicationTests {
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
try (GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()))) {
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package sample.undertow;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -73,7 +74,7 @@ public class SampleUndertowApplicationTests {
|
||||
|
||||
try (GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()))) {
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -67,7 +68,7 @@ public class HelloWebSecurityApplicationTests {
|
||||
public void userAuthenticates() throws Exception {
|
||||
this.request.addHeader("Accept", "application/json");
|
||||
this.request.addHeader("Authorization", "Basic " + new String(
|
||||
Base64.getEncoder().encode("user:password".getBytes("UTF-8"))));
|
||||
Base64.getEncoder().encode("user:password".getBytes(StandardCharsets.UTF_8))));
|
||||
|
||||
this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user