Skip to content

Commit 43df06b

Browse files
author
May
authored
Replace anonymous inner classes with lambda expressions
Closes gh-25319
1 parent ba5f4f5 commit 43df06b

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,24 @@ public URI getURI() {
7676
protected ListenableFuture<ClientHttpResponse> executeInternal(
7777
final HttpHeaders headers, final byte[] bufferedOutput) throws IOException {
7878

79-
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
80-
@Override
81-
public ClientHttpResponse call() throws Exception {
82-
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
83-
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
84-
if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
85-
connection.setDoOutput(false);
86-
}
87-
if (connection.getDoOutput() && outputStreaming) {
88-
connection.setFixedLengthStreamingMode(bufferedOutput.length);
89-
}
90-
connection.connect();
91-
if (connection.getDoOutput()) {
92-
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());
93-
}
94-
else {
95-
// Immediately trigger the request in a no-output scenario as well
96-
connection.getResponseCode();
97-
}
98-
return new SimpleClientHttpResponse(connection);
79+
return this.taskExecutor.submitListenable(() -> {
80+
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
81+
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
82+
if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
83+
connection.setDoOutput(false);
9984
}
85+
if (connection.getDoOutput() && outputStreaming) {
86+
connection.setFixedLengthStreamingMode(bufferedOutput.length);
87+
}
88+
connection.connect();
89+
if (connection.getDoOutput()) {
90+
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());
91+
}
92+
else {
93+
// Immediately trigger the request in a no-output scenario as well
94+
connection.getResponseCode();
95+
}
96+
return new SimpleClientHttpResponse(connection);
10097
});
10198
}
10299

spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,22 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
103103

104104
@Override
105105
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
106-
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
107-
@Override
108-
public ClientHttpResponse call() throws Exception {
109-
try {
110-
if (body != null) {
111-
body.close();
112-
}
113-
else {
114-
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
115-
connection.connect();
116-
// Immediately trigger the request in a no-output scenario as well
117-
connection.getResponseCode();
118-
}
106+
return this.taskExecutor.submitListenable(() -> {
107+
try {
108+
if (body != null) {
109+
body.close();
119110
}
120-
catch (IOException ex) {
121-
// ignore
111+
else {
112+
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
113+
connection.connect();
114+
// Immediately trigger the request in a no-output scenario as well
115+
connection.getResponseCode();
122116
}
123-
return new SimpleClientHttpResponse(connection);
124117
}
118+
catch (IOException ex) {
119+
// ignore
120+
}
121+
return new SimpleClientHttpResponse(connection);
125122
});
126123

127124
}

0 commit comments

Comments
 (0)