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:
Andy Wilkinson
2017-05-23 17:24:01 +01:00
parent 3e797c326a
commit d5438c299c
78 changed files with 284 additions and 703 deletions

View File

@@ -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();

View File

@@ -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) {