Utilize StandardCharsets
Closes gh-10972
This commit is contained in:
committed by
Stephane Nicoll
parent
e9c81bf702
commit
bd0dcfb172
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user