Skip to content

Commit fc52ddc

Browse files
committed
Polish
1 parent d8f4d37 commit fc52ddc

File tree

9 files changed

+56
-57
lines changed

9 files changed

+56
-57
lines changed

spring-core/src/main/java/org/springframework/core/codec/Decoder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.core.codec;
1818

19-
import java.util.Collections;
2019
import java.util.List;
2120
import java.util.Map;
2221

spring-core/src/main/java/org/springframework/core/codec/Encoder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.core.codec;
1818

19-
import java.util.Collections;
2019
import java.util.List;
2120
import java.util.Map;
2221

spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void toConfiguration() throws Exception {
162162
private static class DummyMessageWriter implements HttpMessageWriter<Object> {
163163

164164
@Override
165-
public boolean canWrite(ResolvableType type, MediaType mediaType, Map<String, Object> hints) {
165+
public boolean canWrite(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints) {
166166
return false;
167167
}
168168

@@ -172,8 +172,8 @@ public List<MediaType> getWritableMediaTypes() {
172172
}
173173

174174
@Override
175-
public Mono<Void> write(Publisher<?> inputStream, ResolvableType type,
176-
MediaType contentType,
175+
public Mono<Void> write(Publisher<?> inputStream, ResolvableType elementType,
176+
MediaType mediaType,
177177
ReactiveHttpOutputMessage outputMessage,
178178
Map<String, Object> hints) {
179179
return Mono.empty();
@@ -183,7 +183,7 @@ public Mono<Void> write(Publisher<?> inputStream, ResolvableType type,
183183
private static class DummyMessageReader implements HttpMessageReader<Object> {
184184

185185
@Override
186-
public boolean canRead(ResolvableType type, MediaType mediaType, Map<String, Object> hints) {
186+
public boolean canRead(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints) {
187187
return false;
188188
}
189189

@@ -193,13 +193,13 @@ public List<MediaType> getReadableMediaTypes() {
193193
}
194194

195195
@Override
196-
public Flux<Object> read(ResolvableType type, ReactiveHttpInputMessage inputMessage,
196+
public Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage,
197197
Map<String, Object> hints) {
198198
return Flux.empty();
199199
}
200200

201201
@Override
202-
public Mono<Object> readMono(ResolvableType type, ReactiveHttpInputMessage inputMessage,
202+
public Mono<Object> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage,
203203
Map<String, Object> hints) {
204204
return Mono.empty();
205205
}

spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public DecoderHttpMessageReader(Decoder<T> decoder) {
5656

5757

5858
@Override
59-
public boolean canRead(ResolvableType type, MediaType mediaType, Map<String, Object> hints) {
60-
return this.decoder != null && this.decoder.canDecode(type, mediaType, hints);
59+
public boolean canRead(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints) {
60+
return this.decoder != null && this.decoder.canDecode(elementType, mediaType, hints);
6161
}
6262

6363
@Override
@@ -67,21 +67,21 @@ public List<MediaType> getReadableMediaTypes() {
6767

6868

6969
@Override
70-
public Flux<T> read(ResolvableType type, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
70+
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
7171
if (this.decoder == null) {
7272
return Flux.error(new IllegalStateException("No decoder set"));
7373
}
7474
MediaType contentType = getContentType(inputMessage);
75-
return this.decoder.decode(inputMessage.getBody(), type, contentType, hints);
75+
return this.decoder.decode(inputMessage.getBody(), elementType, contentType, hints);
7676
}
7777

7878
@Override
79-
public Mono<T> readMono(ResolvableType type, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
79+
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
8080
if (this.decoder == null) {
8181
return Mono.error(new IllegalStateException("No decoder set"));
8282
}
8383
MediaType contentType = getContentType(inputMessage);
84-
return this.decoder.decodeToMono(inputMessage.getBody(), type, contentType, hints);
84+
return this.decoder.decodeToMono(inputMessage.getBody(), elementType, contentType, hints);
8585
}
8686

8787
private MediaType getContentType(ReactiveHttpInputMessage inputMessage) {

spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public EncoderHttpMessageWriter(Encoder<T> encoder) {
6060

6161

6262
@Override
63-
public boolean canWrite(ResolvableType type, MediaType mediaType, Map<String, Object> hints) {
64-
return this.encoder != null && this.encoder.canEncode(type, mediaType, hints);
63+
public boolean canWrite(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints) {
64+
return this.encoder != null && this.encoder.canEncode(elementType, mediaType, hints);
6565
}
6666

6767
@Override
@@ -71,8 +71,8 @@ public List<MediaType> getWritableMediaTypes() {
7171

7272

7373
@Override
74-
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType type,
75-
MediaType contentType, ReactiveHttpOutputMessage outputMessage,
74+
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
75+
MediaType mediaType, ReactiveHttpOutputMessage outputMessage,
7676
Map<String, Object> hints) {
7777

7878
if (this.encoder == null) {
@@ -81,27 +81,27 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType type,
8181

8282
HttpHeaders headers = outputMessage.getHeaders();
8383
if (headers.getContentType() == null) {
84-
MediaType contentTypeToUse = contentType;
85-
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
86-
contentTypeToUse = getDefaultContentType(type);
84+
MediaType contentTypeToUse = mediaType;
85+
if (mediaType == null || mediaType.isWildcardType() || mediaType.isWildcardSubtype()) {
86+
contentTypeToUse = getDefaultContentType(elementType);
8787
}
88-
else if (MediaType.APPLICATION_OCTET_STREAM.equals(contentType)) {
89-
MediaType mediaType = getDefaultContentType(type);
90-
contentTypeToUse = (mediaType != null ? mediaType : contentTypeToUse);
88+
else if (MediaType.APPLICATION_OCTET_STREAM.equals(mediaType)) {
89+
MediaType contentType = getDefaultContentType(elementType);
90+
contentTypeToUse = (contentType != null ? contentType : contentTypeToUse);
9191
}
9292
if (contentTypeToUse != null) {
9393
if (contentTypeToUse.getCharset() == null) {
94-
MediaType mediaType = getDefaultContentType(type);
95-
if (mediaType != null && mediaType.getCharset() != null) {
96-
contentTypeToUse = new MediaType(contentTypeToUse, mediaType.getCharset());
94+
MediaType contentType = getDefaultContentType(elementType);
95+
if (contentType != null && contentType.getCharset() != null) {
96+
contentTypeToUse = new MediaType(contentTypeToUse, contentType.getCharset());
9797
}
9898
}
9999
headers.setContentType(contentTypeToUse);
100100
}
101101
}
102102

103103
DataBufferFactory bufferFactory = outputMessage.bufferFactory();
104-
Flux<DataBuffer> body = this.encoder.encode(inputStream, bufferFactory, type, contentType, hints);
104+
Flux<DataBuffer> body = this.encoder.encode(inputStream, bufferFactory, elementType, mediaType, hints);
105105
return outputMessage.writeWith(body);
106106
}
107107

spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.http.codec;
1818

19-
import java.util.Collections;
2019
import java.util.List;
2120
import java.util.Map;
2221

@@ -40,35 +39,35 @@ public interface HttpMessageReader<T> {
4039

4140
/**
4241
* Indicates whether the given class can be read by this converter.
43-
* @param type the type to test for readability
42+
* @param elementType the stream element type to test for readability
4443
* @param mediaType the media type to read, can be {@code null} if not specified.
4544
* Typically the value of a {@code Content-Type} header.
4645
* @param hints additional information about how to do read
4746
* @return {@code true} if readable; {@code false} otherwise
4847
*/
49-
boolean canRead(ResolvableType type, MediaType mediaType, Map<String, Object> hints);
48+
boolean canRead(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints);
5049

5150
/**
5251
* Read a {@link Flux} of the given type form the given input message, and returns it.
53-
* @param type the type of object to return. This type must have previously been
52+
* @param elementType the stream element type to return. This type must have previously been
5453
* passed to the {@link #canRead canRead} method of this interface, which must have
5554
* returned {@code true}.
5655
* @param inputMessage the HTTP input message to read from
5756
* @param hints additional information about how to do read
5857
* @return the converted {@link Flux} of elements
5958
*/
60-
Flux<T> read(ResolvableType type, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints);
59+
Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints);
6160

6261
/**
6362
* Read a {@link Mono} of the given type form the given input message, and returns it.
64-
* @param type the type of object to return. This type must have previously been
63+
* @param elementType the stream element type to return. This type must have previously been
6564
* passed to the {@link #canRead canRead} method of this interface, which must have
6665
* returned {@code true}.
6766
* @param inputMessage the HTTP input message to read from
6867
* @param hints additional information about how to do read
6968
* @return the converted {@link Mono} of object
7069
*/
71-
Mono<T> readMono(ResolvableType type, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints);
70+
Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints);
7271

7372
/**
7473
* Return the list of {@link MediaType} objects that can be read by this converter.

spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.http.codec;
1818

19-
import java.util.Collections;
2019
import java.util.List;
2120
import java.util.Map;
2221

@@ -40,26 +39,29 @@ public interface HttpMessageWriter<T> {
4039

4140
/**
4241
* Indicates whether the given class can be written by this converter.
43-
* @param type the class to test for writability
42+
* @param elementType the stream element type to test for writability
4443
* @param mediaType the media type to write, can be {@code null} if not specified.
4544
* Typically the value of an {@code Accept} header.
46-
* @param hints additional information about how to do write
45+
* @param hints additional information about how to write
4746
* @return {@code true} if writable; {@code false} otherwise
4847
*/
49-
boolean canWrite(ResolvableType type, MediaType mediaType, Map<String, Object> hints);
48+
boolean canWrite(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints);
5049

5150
/**
5251
* Write an given object to the given output message.
5352
* @param inputStream the input stream to write
54-
* @param type the stream element type to process.
55-
* @param contentType the content type to use when writing. May be {@code null} to
56-
* indicate that the default content type of the converter must be used.
53+
* @param elementType the stream element type to process. This type must have previously
54+
* been passed to the {@link #canWrite} canWrite} method of this interface, which must
55+
* have returned {@code true}.
56+
* @param mediaType the content type to use when writing, typically the value of an
57+
* {@code Accept} header. May be {@code null} to indicate that the default content
58+
* type of the converter must be used.
5759
* @param outputMessage the message to write to
58-
* @param hints additional information about how to do write
60+
* @param hints additional information about how to write
5961
* @return the converted {@link Mono} of object
6062
*/
61-
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType type,
62-
MediaType contentType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints);
63+
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
64+
MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints);
6365

6466
/**
6567
* Return the list of {@link MediaType} objects that can be written by this converter.

spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ public ResourceHttpMessageWriter(int bufferSize) {
5959

6060

6161
@Override
62-
public Mono<Void> write(Publisher<? extends Resource> inputStream, ResolvableType type,
63-
MediaType contentType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {
62+
public Mono<Void> write(Publisher<? extends Resource> inputStream, ResolvableType elementType,
63+
MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {
6464

6565
return Mono.from(Flux.from(inputStream).
6666
take(1).
6767
concatMap(resource -> {
6868
HttpHeaders headers = outputMessage.getHeaders();
69-
addHeaders(headers, resource, contentType);
70-
return writeContent(resource, type, outputMessage, hints);
69+
addHeaders(headers, resource, mediaType);
70+
return writeContent(resource, elementType, outputMessage, hints);
7171
}));
7272
}
7373

74-
protected void addHeaders(HttpHeaders headers, Resource resource, MediaType contentType) {
74+
protected void addHeaders(HttpHeaders headers, Resource resource, MediaType mediaType) {
7575
if (headers.getContentType() == null) {
76-
if (contentType == null || !contentType.isConcrete() ||
77-
MediaType.APPLICATION_OCTET_STREAM.equals(contentType)) {
78-
contentType = Optional.ofNullable(MediaTypeFactory.getMediaType(resource)).
76+
if (mediaType == null || !mediaType.isConcrete() ||
77+
MediaType.APPLICATION_OCTET_STREAM.equals(mediaType)) {
78+
mediaType = Optional.ofNullable(MediaTypeFactory.getMediaType(resource)).
7979
orElse(MediaType.APPLICATION_OCTET_STREAM);
8080
}
81-
headers.setContentType(contentType);
81+
headers.setContentType(mediaType);
8282
}
8383
if (headers.getContentLength() < 0) {
8484
contentLength(resource).ifPresent(headers::setContentLength);

spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ServerSentEventHttpMessageWriter(List<Encoder<?>> dataEncoders) {
6262
}
6363

6464
@Override
65-
public boolean canWrite(ResolvableType type, MediaType mediaType, Map<String, Object> hints) {
65+
public boolean canWrite(ResolvableType elementType, MediaType mediaType, Map<String, Object> hints) {
6666
return mediaType == null || TEXT_EVENT_STREAM.isCompatibleWith(mediaType);
6767
}
6868

@@ -72,13 +72,13 @@ public List<MediaType> getWritableMediaTypes() {
7272
}
7373

7474
@Override
75-
public Mono<Void> write(Publisher<?> inputStream, ResolvableType type, MediaType contentType,
75+
public Mono<Void> write(Publisher<?> inputStream, ResolvableType elementType, MediaType mediaType,
7676
ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {
7777

7878
outputMessage.getHeaders().setContentType(TEXT_EVENT_STREAM);
7979

8080
DataBufferFactory bufferFactory = outputMessage.bufferFactory();
81-
Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, type, hints);
81+
Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, elementType, hints);
8282

8383
return outputMessage.writeAndFlushWith(body);
8484
}

0 commit comments

Comments
 (0)