Skip to content

Commit 9a20ec9

Browse files
committed
Polishing
1 parent 03beee7 commit 9a20ec9

File tree

6 files changed

+32
-47
lines changed

6 files changed

+32
-47
lines changed

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -177,9 +177,9 @@ public int hashCode() {
177177
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
178178
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
179179
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
180-
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
181-
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
182-
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
180+
result = 31 * result + (this.creationDate != null ? this.creationDate.hashCode() : 0);
181+
result = 31 * result + (this.modificationDate != null ? this.modificationDate.hashCode() : 0);
182+
result = 31 * result + (this.readDate != null ? this.readDate.hashCode() : 0);
183183
return result;
184184
}
185185

@@ -198,7 +198,7 @@ public String toString() {
198198
sb.append(this.name).append('\"');
199199
}
200200
if (this.filename != null) {
201-
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
201+
if (this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
202202
sb.append("; filename=\"");
203203
sb.append(this.filename).append('\"');
204204
}
@@ -441,12 +441,12 @@ private static String encodeHeaderFieldParam(String input, Charset charset) {
441441
public interface Builder {
442442

443443
/**
444-
* Set the value of the {@literal name} parameter
444+
* Set the value of the {@literal name} parameter.
445445
*/
446446
Builder name(String name);
447447

448448
/**
449-
* Set the value of the {@literal filename} parameter
449+
* Set the value of the {@literal filename} parameter.
450450
*/
451451
Builder filename(String filename);
452452

@@ -463,7 +463,7 @@ public interface Builder {
463463
Builder filename(String filename, Charset charset);
464464

465465
/**
466-
* Set the value of the {@literal size} parameter
466+
* Set the value of the {@literal size} parameter.
467467
*/
468468
Builder size(Long size);
469469

@@ -483,7 +483,7 @@ public interface Builder {
483483
Builder readDate(ZonedDateTime readDate);
484484

485485
/**
486-
* Build the content disposition
486+
* Build the content disposition.
487487
*/
488488
ContentDisposition build();
489489
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/GzipResourceResolver.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -57,7 +57,7 @@ protected Mono<Resource> resolveResourceInternal(@Nullable ServerWebExchange exc
5757
}
5858
}
5959
catch (IOException ex) {
60-
logger.trace("No gzipped resource for [" + resource.getFilename() + "]", ex);
60+
logger.trace("No gzip resource for [" + resource.getFilename() + "]", ex);
6161
}
6262
}
6363
return resource;
@@ -77,6 +77,9 @@ protected Mono<String> resolveUrlPathInternal(String resourceUrlPath,
7777
}
7878

7979

80+
/**
81+
* A gzipped {@link HttpResource}.
82+
*/
8083
static final class GzippedResource extends AbstractResource implements HttpResource {
8184

8285
private final Resource original;
@@ -156,13 +159,8 @@ public String getDescription() {
156159

157160
@Override
158161
public HttpHeaders getResponseHeaders() {
159-
HttpHeaders headers;
160-
if(this.original instanceof HttpResource) {
161-
headers = ((HttpResource) this.original).getResponseHeaders();
162-
}
163-
else {
164-
headers = new HttpHeaders();
165-
}
162+
HttpHeaders headers = (this.original instanceof HttpResource ?
163+
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
166164
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
167165
return headers;
168166
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,23 +323,18 @@ public Resource createRelative(String relativePath) throws IOException {
323323

324324
@Override
325325
public String getDescription() {
326-
return original.getDescription();
326+
return this.original.getDescription();
327327
}
328328

329329
@Override
330330
public InputStream getInputStream() throws IOException {
331-
return original.getInputStream();
331+
return this.original.getInputStream();
332332
}
333333

334334
@Override
335335
public HttpHeaders getResponseHeaders() {
336-
HttpHeaders headers;
337-
if(this.original instanceof HttpResource) {
338-
headers = ((HttpResource) this.original).getResponseHeaders();
339-
}
340-
else {
341-
headers = new HttpHeaders();
342-
}
336+
HttpHeaders headers = (this.original instanceof HttpResource ?
337+
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
343338
headers.setETag("\"" + this.version + "\"");
344339
return headers;
345340
}

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,13 @@ else if (returnValue instanceof HttpHeaders) {
153153

154154
HttpHeaders entityHeaders = httpEntity.getHeaders();
155155
HttpHeaders responseHeaders = exchange.getResponse().getHeaders();
156-
157156
if (!entityHeaders.isEmpty()) {
158157
entityHeaders.entrySet().stream()
159158
.filter(entry -> !responseHeaders.containsKey(entry.getKey()))
160159
.forEach(entry -> responseHeaders.put(entry.getKey(), entry.getValue()));
161160
}
162161

163-
if(httpEntity.getBody() == null || returnValue instanceof HttpHeaders) {
162+
if (httpEntity.getBody() == null || returnValue instanceof HttpHeaders) {
164163
return exchange.getResponse().setComplete();
165164
}
166165

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -59,7 +59,7 @@ protected Resource resolveResourceInternal(@Nullable HttpServletRequest request,
5959
}
6060
}
6161
catch (IOException ex) {
62-
logger.trace("No gzipped resource for [" + resource.getFilename() + "]", ex);
62+
logger.trace("No gzip resource for [" + resource.getFilename() + "]", ex);
6363
}
6464

6565
return resource;
@@ -78,6 +78,9 @@ protected String resolveUrlPathInternal(String resourceUrlPath,
7878
}
7979

8080

81+
/**
82+
* A gzipped {@link HttpResource}.
83+
*/
8184
static final class GzippedResource extends AbstractResource implements HttpResource {
8285

8386
private final Resource original;
@@ -157,13 +160,8 @@ public String getDescription() {
157160

158161
@Override
159162
public HttpHeaders getResponseHeaders() {
160-
HttpHeaders headers;
161-
if (this.original instanceof HttpResource) {
162-
headers = ((HttpResource) this.original).getResponseHeaders();
163-
}
164-
else {
165-
headers = new HttpHeaders();
166-
}
163+
HttpHeaders headers = (this.original instanceof HttpResource ?
164+
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
167165
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
168166
return headers;
169167
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,18 @@ public Resource createRelative(String relativePath) throws IOException {
316316

317317
@Override
318318
public String getDescription() {
319-
return original.getDescription();
319+
return this.original.getDescription();
320320
}
321321

322322
@Override
323323
public InputStream getInputStream() throws IOException {
324-
return original.getInputStream();
324+
return this.original.getInputStream();
325325
}
326326

327327
@Override
328328
public HttpHeaders getResponseHeaders() {
329-
HttpHeaders headers;
330-
if (this.original instanceof HttpResource) {
331-
headers = ((HttpResource) this.original).getResponseHeaders();
332-
}
333-
else {
334-
headers = new HttpHeaders();
335-
}
329+
HttpHeaders headers = (this.original instanceof HttpResource ?
330+
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
336331
headers.setETag("\"" + this.version + "\"");
337332
return headers;
338333
}

0 commit comments

Comments
 (0)