Use 'toString(Charset)' instead of 'toString(String)' for encodings (#27646)
Co-authored-by: 홍성민(SungMin Hong)/Platform Engineering팀/11ST <devmonster@11stcorp.com>
This commit is contained in:
@@ -90,7 +90,7 @@ class SortedProperties extends Properties {
|
||||
public void store(OutputStream out, @Nullable String comments) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
super.store(baos, (this.omitComments ? null : comments));
|
||||
String contents = baos.toString(StandardCharsets.ISO_8859_1.name());
|
||||
String contents = baos.toString(StandardCharsets.ISO_8859_1);
|
||||
for (String line : contents.split(EOL)) {
|
||||
if (!(this.omitComments && line.startsWith("#"))) {
|
||||
out.write((line + EOL).getBytes(StandardCharsets.ISO_8859_1));
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.core.convert.support;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
@@ -36,7 +37,7 @@ final class PropertiesToStringConverter implements Converter<Properties, String>
|
||||
try {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(256);
|
||||
source.store(os, null);
|
||||
return os.toString("ISO-8859-1");
|
||||
return os.toString(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// Should never happen.
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@@ -105,14 +104,8 @@ public abstract class StreamUtils {
|
||||
public static String copyToString(ByteArrayOutputStream baos, Charset charset) {
|
||||
Assert.notNull(baos, "No ByteArrayOutputStream specified");
|
||||
Assert.notNull(charset, "No Charset specified");
|
||||
try {
|
||||
// Can be replaced with toString(Charset) call in Java 10+
|
||||
return baos.toString(charset.name());
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
// Should never happen
|
||||
throw new IllegalArgumentException("Invalid charset name: " + charset, ex);
|
||||
}
|
||||
|
||||
return baos.toString(charset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user