Replace try with try-with-resources
Update existing try/finally/close blocks to use "try with resources" See gh-9781
This commit is contained in:
parent
798fe5ed53
commit
d16af43664
|
|
@ -170,10 +170,9 @@ public class TunnelClient implements SmartInitializingSingleton {
|
||||||
|
|
||||||
private void handleConnection(SocketChannel socketChannel) throws Exception {
|
private void handleConnection(SocketChannel socketChannel) throws Exception {
|
||||||
Closeable closeable = new SocketCloseable(socketChannel);
|
Closeable closeable = new SocketCloseable(socketChannel);
|
||||||
WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection
|
|
||||||
.open(socketChannel, closeable);
|
|
||||||
TunnelClient.this.listeners.fireOpenEvent(socketChannel);
|
TunnelClient.this.listeners.fireOpenEvent(socketChannel);
|
||||||
try {
|
try (WritableByteChannel outputChannel = TunnelClient.this.tunnelConnection
|
||||||
|
.open(socketChannel, closeable)) {
|
||||||
logger.trace("Accepted connection to tunnel client from "
|
logger.trace("Accepted connection to tunnel client from "
|
||||||
+ socketChannel.socket().getRemoteSocketAddress());
|
+ socketChannel.socket().getRemoteSocketAddress());
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
@ -189,9 +188,6 @@ public class TunnelClient implements SmartInitializingSingleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
outputChannel.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopAcceptingConnections() {
|
protected void stopAcceptingConnections() {
|
||||||
|
|
|
||||||
|
|
@ -186,8 +186,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
||||||
|
|
||||||
private long getNestedLibraryTime(File file) {
|
private long getNestedLibraryTime(File file) {
|
||||||
try {
|
try {
|
||||||
JarFile jarFile = new JarFile(file);
|
try (JarFile jarFile = new JarFile(file)) {
|
||||||
try {
|
|
||||||
Enumeration<JarEntry> entries = jarFile.entries();
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
JarEntry entry = entries.nextElement();
|
JarEntry entry = entries.nextElement();
|
||||||
|
|
@ -196,9 +195,6 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
jarFile.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
// Ignore and just use the source file timestamp
|
// Ignore and just use the source file timestamp
|
||||||
|
|
@ -381,13 +377,9 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
CrcAndSize(File file) throws IOException {
|
CrcAndSize(File file) throws IOException {
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
try (FileInputStream inputStream = new FileInputStream(file)) {
|
||||||
try {
|
|
||||||
load(inputStream);
|
load(inputStream);
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CrcAndSize(InputStream inputStream) throws IOException {
|
CrcAndSize(InputStream inputStream) throws IOException {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue