Skip to content

Commit 9aa43fc

Browse files
jhoellerunknown
authored and
unknown
committed
reintroduced static DEFAULT_CHARSET field
Issue: SPR-9487
1 parent 2ec7834 commit 9aa43fc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,30 @@
3232
/**
3333
* Implementation of {@link HttpMessageConverter} that can read and write strings.
3434
*
35-
* <p>By default, this converter supports all media types (<code>&#42;&#47;&#42;</code>), and writes with a {@code
36-
* Content-Type} of {@code text/plain}. This can be overridden by setting the {@link
37-
* #setSupportedMediaTypes(java.util.List) supportedMediaTypes} property.
35+
* <p>By default, this converter supports all media types (<code>&#42;&#47;&#42;</code>),
36+
* and writes with a {@code Content-Type} of {@code text/plain}. This can be overridden
37+
* by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
3838
*
3939
* @author Arjen Poutsma
4040
* @since 3.0
4141
*/
4242
public class StringHttpMessageConverter extends AbstractHttpMessageConverter<String> {
4343

44+
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
45+
4446
private final Charset defaultCharset;
4547

4648
private final List<Charset> availableCharsets;
4749

4850
private boolean writeAcceptCharset = true;
4951

52+
5053
/**
5154
* A default constructor that uses {@code "ISO-8859-1"} as the default charset.
5255
* @see #StringHttpMessageConverter(Charset)
5356
*/
5457
public StringHttpMessageConverter() {
55-
this(Charset.forName("ISO-8859-1"));
58+
this(DEFAULT_CHARSET);
5659
}
5760

5861
/**
@@ -73,6 +76,7 @@ public void setWriteAcceptCharset(boolean writeAcceptCharset) {
7376
this.writeAcceptCharset = writeAcceptCharset;
7477
}
7578

79+
7680
@Override
7781
public boolean supports(Class<?> clazz) {
7882
return String.class.equals(clazz);
@@ -92,13 +96,13 @@ protected Long getContentLength(String s, MediaType contentType) {
9296
}
9397
catch (UnsupportedEncodingException ex) {
9498
// should not occur
95-
throw new InternalError(ex.getMessage());
99+
throw new IllegalStateException(ex);
96100
}
97101
}
98102

99103
@Override
100104
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
101-
if (writeAcceptCharset) {
105+
if (this.writeAcceptCharset) {
102106
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
103107
}
104108
Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
@@ -107,9 +111,7 @@ protected void writeInternal(String s, HttpOutputMessage outputMessage) throws I
107111

108112
/**
109113
* Return the list of supported {@link Charset}.
110-
*
111114
* <p>By default, returns {@link Charset#availableCharsets()}. Can be overridden in subclasses.
112-
*
113115
* @return the list of accepted charsets
114116
*/
115117
protected List<Charset> getAcceptedCharsets() {

0 commit comments

Comments
 (0)