Skip to content

Commit 9ac661d

Browse files
committed
Polishing
1 parent 57aa2af commit 9ac661d

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public HttpHeaders getHeaders() {
200200
/**
201201
* Add default headers to the output message.
202202
* <p>This implementation delegates to {@link #getDefaultContentType(Object)} if a content
203-
* type was not provided, calls {@link #getContentLength}, and sets the corresponding headers
203+
* type was not provided, calls {@link #getContentLength}, and sets the corresponding headers.
204204
* @since 4.2
205205
*/
206206
protected void addDefaultHeaders(HttpHeaders headers, T t, MediaType contentType) throws IOException{

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -32,15 +32,19 @@
3232
* overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
3333
*
3434
* @author Arjen Poutsma
35+
* @author Juergen Hoeller
3536
* @since 3.0
3637
*/
3738
public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<byte[]> {
3839

39-
/** Creates a new instance of the {@code ByteArrayHttpMessageConverter}. */
40+
/**
41+
* Create a new instance of the {@code ByteArrayHttpMessageConverter}.
42+
*/
4043
public ByteArrayHttpMessageConverter() {
4144
super(new MediaType("application", "octet-stream"), MediaType.ALL);
4245
}
4346

47+
4448
@Override
4549
public boolean supports(Class<?> clazz) {
4650
return byte[].class == clazz;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -255,7 +255,7 @@ private void writeForm(MultiValueMap<String, String> form, MediaType contentType
255255
Charset charset;
256256
if (contentType != null) {
257257
outputMessage.getHeaders().setContentType(contentType);
258-
charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
258+
charset = (contentType.getCharSet() != null ? contentType.getCharSet() : this.charset);
259259
}
260260
else {
261261
outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -29,11 +29,12 @@
2929
* An {@code HttpMessageConverter} that uses {@link StringHttpMessageConverter}
3030
* for reading and writing content and a {@link ConversionService} for converting
3131
* the String content to and from the target object type.
32-
* <p>
33-
* By default, this converter supports the media type {@code text/plain} only.
34-
* This can be overridden by setting the
35-
* {@link #setSupportedMediaTypes supportedMediaTypes} property.
36-
* Example of usage:
32+
*
33+
* <p>By default, this converter supports the media type {@code text/plain} only.
34+
* This can be overridden through the {@link #setSupportedMediaTypes supportedMediaTypes}
35+
* property.
36+
*
37+
* <p>A usage example:
3738
*
3839
* <pre class="code">
3940
* &lt;bean class="org.springframework.http.converter.ObjectToStringHttpMessageConverter">
@@ -49,38 +50,35 @@
4950
*/
5051
public class ObjectToStringHttpMessageConverter extends AbstractHttpMessageConverter<Object> {
5152

52-
private ConversionService conversionService;
53+
private final ConversionService conversionService;
5354

54-
private StringHttpMessageConverter stringHttpMessageConverter;
55+
private final StringHttpMessageConverter stringHttpMessageConverter;
5556

5657

5758
/**
5859
* A constructor accepting a {@code ConversionService} to use to convert the
59-
* (String) message body to/from the target class type. This constructor
60-
* uses {@link StringHttpMessageConverter#DEFAULT_CHARSET} as the default
61-
* charset.
62-
*
60+
* (String) message body to/from the target class type. This constructor uses
61+
* {@link StringHttpMessageConverter#DEFAULT_CHARSET} as the default charset.
6362
* @param conversionService the conversion service
6463
*/
6564
public ObjectToStringHttpMessageConverter(ConversionService conversionService) {
6665
this(conversionService, StringHttpMessageConverter.DEFAULT_CHARSET);
6766
}
6867

6968
/**
70-
* A constructor accepting a {@code ConversionService} as well as a default
71-
* charset.
72-
*
69+
* A constructor accepting a {@code ConversionService} as well as a default charset.
7370
* @param conversionService the conversion service
7471
* @param defaultCharset the default charset
7572
*/
7673
public ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset) {
7774
super(new MediaType("text", "plain", defaultCharset));
7875

79-
Assert.notNull(conversionService, "conversionService is required");
76+
Assert.notNull(conversionService, "ConversionService is required");
8077
this.conversionService = conversionService;
8178
this.stringHttpMessageConverter = new StringHttpMessageConverter(defaultCharset);
8279
}
8380

81+
8482
/**
8583
* Indicates whether the {@code Accept-Charset} should be written to any outgoing request.
8684
* <p>Default is {@code true}.
@@ -89,6 +87,7 @@ public void setWriteAcceptCharset(boolean writeAcceptCharset) {
8987
this.stringHttpMessageConverter.setWriteAcceptCharset(writeAcceptCharset);
9088
}
9189

90+
9291
@Override
9392
public boolean canRead(Class<?> clazz, MediaType mediaType) {
9493
return this.conversionService.canConvert(String.class, clazz) && canRead(mediaType);
@@ -106,15 +105,15 @@ protected boolean supports(Class<?> clazz) {
106105
}
107106

108107
@Override
109-
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException {
108+
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException {
110109
String value = this.stringHttpMessageConverter.readInternal(String.class, inputMessage);
111110
return this.conversionService.convert(value, clazz);
112111
}
113112

114113
@Override
115114
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException {
116-
String s = this.conversionService.convert(obj, String.class);
117-
this.stringHttpMessageConverter.writeInternal(s, outputMessage);
115+
String value = this.conversionService.convert(obj, String.class);
116+
this.stringHttpMessageConverter.writeInternal(value, outputMessage);
118117
}
119118

120119
@Override

0 commit comments

Comments
 (0)