Use try-with-resources language construct where feasible

Closes gh-2063

Co-authored-by: igor-suhorukov <igor.suhorukov@gmail.com>
This commit is contained in:
Sam Brannen
2020-06-16 22:57:45 +02:00
parent 456d2c46e3
commit 8099fc8178
23 changed files with 179 additions and 394 deletions

View File

@@ -166,13 +166,9 @@ public abstract class AbstractHttpInvokerRequestExecutor implements HttpInvokerR
* @see #doWriteRemoteInvocation
*/
protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(decorateOutputStream(os));
try {
try (ObjectOutputStream oos = new ObjectOutputStream(decorateOutputStream(os))) {
doWriteRemoteInvocation(invocation, oos);
}
finally {
oos.close();
}
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -113,13 +113,9 @@ public class HttpInvokerServiceExporter extends RemoteInvocationSerializingExpor
protected RemoteInvocation readRemoteInvocation(HttpServletRequest request, InputStream is)
throws IOException, ClassNotFoundException {
ObjectInputStream ois = createObjectInputStream(decorateInputStream(request, is));
try {
try (ObjectInputStream ois = createObjectInputStream(decorateInputStream(request, is))) {
return doReadRemoteInvocation(ois);
}
finally {
ois.close();
}
}
/**
@@ -170,14 +166,10 @@ public class HttpInvokerServiceExporter extends RemoteInvocationSerializingExpor
HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result, OutputStream os)
throws IOException {
ObjectOutputStream oos =
createObjectOutputStream(new FlushGuardedOutputStream(decorateOutputStream(request, response, os)));
try {
try (ObjectOutputStream oos =
createObjectOutputStream(new FlushGuardedOutputStream(decorateOutputStream(request, response, os)))) {
doWriteRemoteInvocationResult(result, oos);
}
finally {
oos.close();
}
}
/**