Replace anonymous inner classes with lambda expressions

Closes gh-25319
This commit is contained in:
May 2020-06-27 00:47:38 +08:00 committed by GitHub
parent ba5f4f5414
commit 43df06b905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 36 deletions

View File

@ -76,27 +76,24 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
protected ListenableFuture<ClientHttpResponse> executeInternal(
final HttpHeaders headers, final byte[] bufferedOutput) throws IOException {
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
@Override
public ClientHttpResponse call() throws Exception {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
connection.setDoOutput(false);
}
if (connection.getDoOutput() && outputStreaming) {
connection.setFixedLengthStreamingMode(bufferedOutput.length);
}
connection.connect();
if (connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());
}
else {
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
}
return new SimpleClientHttpResponse(connection);
return this.taskExecutor.submitListenable(() -> {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
if (getMethod() == HttpMethod.DELETE && bufferedOutput.length == 0) {
connection.setDoOutput(false);
}
if (connection.getDoOutput() && outputStreaming) {
connection.setFixedLengthStreamingMode(bufferedOutput.length);
}
connection.connect();
if (connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, connection.getOutputStream());
}
else {
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
}
return new SimpleClientHttpResponse(connection);
});
}

View File

@ -103,25 +103,22 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
return this.taskExecutor.submitListenable(new Callable<ClientHttpResponse>() {
@Override
public ClientHttpResponse call() throws Exception {
try {
if (body != null) {
body.close();
}
else {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
connection.connect();
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
}
return this.taskExecutor.submitListenable(() -> {
try {
if (body != null) {
body.close();
}
catch (IOException ex) {
// ignore
else {
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
connection.connect();
// Immediately trigger the request in a no-output scenario as well
connection.getResponseCode();
}
return new SimpleClientHttpResponse(connection);
}
catch (IOException ex) {
// ignore
}
return new SimpleClientHttpResponse(connection);
});
}