Polish "Use try-with-resources to close resources automatically"
- Apply code formatting - Use try-with-resources in many other places that were missed in the pull request Closes gh-8045
This commit is contained in:
@@ -282,16 +282,10 @@ public class LiveReloadServer {
|
||||
|
||||
private void handle() throws Exception {
|
||||
try {
|
||||
try {
|
||||
OutputStream outputStream = this.socket.getOutputStream();
|
||||
try {
|
||||
Connection connection = createConnection(this.socket,
|
||||
this.inputStream, outputStream);
|
||||
runConnection(connection);
|
||||
}
|
||||
finally {
|
||||
outputStream.close();
|
||||
}
|
||||
try (OutputStream outputStream = this.socket.getOutputStream()) {
|
||||
Connection connection = createConnection(this.socket,
|
||||
this.inputStream, outputStream);
|
||||
runConnection(connection);
|
||||
}
|
||||
finally {
|
||||
this.inputStream.close();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -152,16 +152,12 @@ public class TunnelClient implements SmartInitializingSingleton {
|
||||
public void run() {
|
||||
try {
|
||||
while (this.acceptConnections) {
|
||||
SocketChannel socket = this.serverSocketChannel.accept();
|
||||
try {
|
||||
try (SocketChannel socket = this.serverSocketChannel.accept()) {
|
||||
handleConnection(socket);
|
||||
}
|
||||
catch (AsynchronousCloseException ex) {
|
||||
// Connection has been closed. Keep the server running
|
||||
}
|
||||
finally {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user