Skip to content

Commit e1d6826

Browse files
committed
Polishing
1 parent 6b353e8 commit e1d6826

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
4141

4242
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
4343

44+
4445
private final Charset defaultCharset;
4546

4647
private final List<Charset> availableCharsets;
@@ -66,6 +67,7 @@ public StringHttpMessageConverter(Charset defaultCharset) {
6667
this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
6768
}
6869

70+
6971
/**
7072
* Indicates whether the {@code Accept-Charset} should be written to any outgoing request.
7173
* <p>Default is {@code true}.
@@ -74,6 +76,7 @@ public void setWriteAcceptCharset(boolean writeAcceptCharset) {
7476
this.writeAcceptCharset = writeAcceptCharset;
7577
}
7678

79+
7780
@Override
7881
public boolean supports(Class<?> clazz) {
7982
return String.class.equals(clazz);
@@ -86,10 +89,10 @@ protected String readInternal(Class<? extends String> clazz, HttpInputMessage in
8689
}
8790

8891
@Override
89-
protected Long getContentLength(String s, MediaType contentType) {
92+
protected Long getContentLength(String str, MediaType contentType) {
9093
Charset charset = getContentTypeCharset(contentType);
9194
try {
92-
return (long) s.getBytes(charset.name()).length;
95+
return (long) str.getBytes(charset.name()).length;
9396
}
9497
catch (UnsupportedEncodingException ex) {
9598
// should not occur
@@ -98,17 +101,19 @@ protected Long getContentLength(String s, MediaType contentType) {
98101
}
99102

100103
@Override
101-
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
104+
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException {
102105
if (this.writeAcceptCharset) {
103106
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
104107
}
105108
Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
106-
StreamUtils.copy(s, charset, outputMessage.getBody());
109+
StreamUtils.copy(str, charset, outputMessage.getBody());
107110
}
108111

112+
109113
/**
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.
112117
* @return the list of accepted charsets
113118
*/
114119
protected List<Charset> getAcceptedCharsets() {
@@ -123,4 +128,5 @@ private Charset getContentTypeCharset(MediaType contentType) {
123128
return this.defaultCharset;
124129
}
125130
}
131+
126132
}

0 commit comments

Comments
 (0)