You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2015/08/27 06:53:37 UTC

svn commit: r1698073 - /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java

Author: ggregory
Date: Thu Aug 27 04:53:36 2015
New Revision: 1698073

URL: http://svn.apache.org/r1698073
Log:
Use try-with-resources.

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java?rev=1698073&r1=1698072&r2=1698073&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java Thu Aug 27 04:53:36 2015
@@ -134,8 +134,7 @@ public class TestHttpAsyncHandlerCancell
         endpoint.waitFor();
 
         final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
-        final Socket socket = new Socket("localhost", address.getPort());
-        try {
+        try (final Socket socket = new Socket("localhost", address.getPort())) {
             final OutputStream outstream = socket.getOutputStream();
             final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outstream, "US-ASCII"));
             writer.write("GET /long HTTP/1.1\r\n");
@@ -146,8 +145,6 @@ public class TestHttpAsyncHandlerCancell
             Thread.sleep(250);
 
             writer.close();
-        } finally {
-            socket.close();
         }
 
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
@@ -192,8 +189,7 @@ public class TestHttpAsyncHandlerCancell
         endpoint.waitFor();
 
         final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
-        final Socket socket = new Socket("localhost", address.getPort());
-        try {
+        try (final Socket socket = new Socket("localhost", address.getPort())) {
             final OutputStream outstream = socket.getOutputStream();
             final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outstream, "US-ASCII"));
             writer.write("GET /long HTTP/1.1\r\n");
@@ -204,8 +200,6 @@ public class TestHttpAsyncHandlerCancell
             Thread.sleep(250);
 
             writer.close();
-        } finally {
-            socket.close();
         }
 
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));