1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
41
41
42
42
public static final Charset DEFAULT_CHARSET = Charset .forName ("ISO-8859-1" );
43
43
44
+
44
45
private final Charset defaultCharset ;
45
46
46
47
private final List <Charset > availableCharsets ;
@@ -66,6 +67,7 @@ public StringHttpMessageConverter(Charset defaultCharset) {
66
67
this .availableCharsets = new ArrayList <Charset >(Charset .availableCharsets ().values ());
67
68
}
68
69
70
+
69
71
/**
70
72
* Indicates whether the {@code Accept-Charset} should be written to any outgoing request.
71
73
* <p>Default is {@code true}.
@@ -74,6 +76,7 @@ public void setWriteAcceptCharset(boolean writeAcceptCharset) {
74
76
this .writeAcceptCharset = writeAcceptCharset ;
75
77
}
76
78
79
+
77
80
@ Override
78
81
public boolean supports (Class <?> clazz ) {
79
82
return String .class .equals (clazz );
@@ -86,10 +89,10 @@ protected String readInternal(Class<? extends String> clazz, HttpInputMessage in
86
89
}
87
90
88
91
@ Override
89
- protected Long getContentLength (String s , MediaType contentType ) {
92
+ protected Long getContentLength (String str , MediaType contentType ) {
90
93
Charset charset = getContentTypeCharset (contentType );
91
94
try {
92
- return (long ) s .getBytes (charset .name ()).length ;
95
+ return (long ) str .getBytes (charset .name ()).length ;
93
96
}
94
97
catch (UnsupportedEncodingException ex ) {
95
98
// should not occur
@@ -98,17 +101,19 @@ protected Long getContentLength(String s, MediaType contentType) {
98
101
}
99
102
100
103
@ Override
101
- protected void writeInternal (String s , HttpOutputMessage outputMessage ) throws IOException {
104
+ protected void writeInternal (String str , HttpOutputMessage outputMessage ) throws IOException {
102
105
if (this .writeAcceptCharset ) {
103
106
outputMessage .getHeaders ().setAcceptCharset (getAcceptedCharsets ());
104
107
}
105
108
Charset charset = getContentTypeCharset (outputMessage .getHeaders ().getContentType ());
106
- StreamUtils .copy (s , charset , outputMessage .getBody ());
109
+ StreamUtils .copy (str , charset , outputMessage .getBody ());
107
110
}
108
111
112
+
109
113
/**
110
- * Return the list of supported {@link Charset}.
111
- * <p>By default, returns {@link Charset#availableCharsets()}. Can be overridden in subclasses.
114
+ * Return the list of supported {@link Charset}s.
115
+ * <p>By default, returns {@link Charset#availableCharsets()}.
116
+ * Can be overridden in subclasses.
112
117
* @return the list of accepted charsets
113
118
*/
114
119
protected List <Charset > getAcceptedCharsets () {
@@ -123,4 +128,5 @@ private Charset getContentTypeCharset(MediaType contentType) {
123
128
return this .defaultCharset ;
124
129
}
125
130
}
131
+
126
132
}
0 commit comments