hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1789732 - in /httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl: bootstrap/HttpRequester.java io/BHttpConnectionBase.java io/DefaultBHttpClientConnection.java io/DefaultBHttpServerConnection.java
Date Fri, 31 Mar 2017 19:01:24 GMT
Author: ggregory
Date: Fri Mar 31 19:01:24 2017
New Revision: 1789732

URL: http://svn.apache.org/viewvc?rev=1789732&view=rev
Log:
Fix compiler warning: Use try-with-resources.

Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java?rev=1789732&r1=1789731&r2=1789732&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
Fri Mar 31 19:01:24 2017
@@ -123,8 +123,7 @@ public class HttpRequester implements Au
             final ClassicHttpRequest request,
             final HttpContext context,
             final ResponseHandler<T> responseHandler) throws HttpException, IOException
{
-        final ClassicHttpResponse response = execute(connection, request, context);
-        try {
+        try (final ClassicHttpResponse response = execute(connection, request, context))
{
             final T result = responseHandler.handleResponse(response);
             EntityUtils.consume(response.getEntity());
             final boolean keepAlive = requestExecutor.keepAlive(request, response, connection,
context);
@@ -135,8 +134,6 @@ public class HttpRequester implements Au
         } catch (HttpException | IOException | RuntimeException ex) {
             connection.shutdown();
             throw ex;
-        } finally {
-            response.close();
         }
     }
 
@@ -300,13 +297,10 @@ public class HttpRequester implements Au
             final SocketConfig socketConfig,
             final HttpContext context,
             final ResponseHandler<T> responseHandler) throws HttpException, IOException
{
-        final ClassicHttpResponse response = execute(targetHost, request, socketConfig, context);
-        try {
+        try (final ClassicHttpResponse response = execute(targetHost, request, socketConfig,
context)) {
             final T result = responseHandler.handleResponse(response);
             EntityUtils.consume(response.getEntity());
             return result;
-        } finally {
-            response.close();
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java?rev=1789732&r1=1789731&r2=1789732&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
Fri Mar 31 19:01:24 2017
@@ -215,13 +215,10 @@ class BHttpConnectionBase implements BHt
     public void shutdown() throws IOException {
         final SocketHolder socketHolder = this.socketHolderRef.getAndSet(null);
         if (socketHolder != null) {
-            final Socket socket = socketHolder.getSocket();
             // force abortive close (RST)
-            try {
+            try (final Socket socket = socketHolder.getSocket()) {
                 socket.setSoLinger(true, 0);
             } catch (final IOException ex) {
-            } finally {
-                socket.close();
             }
         }
     }
@@ -230,8 +227,7 @@ class BHttpConnectionBase implements BHt
     public void close() throws IOException {
         final SocketHolder socketHolder = this.socketHolderRef.getAndSet(null);
         if (socketHolder != null) {
-            final Socket socket = socketHolder.getSocket();
-            try {
+            try (final Socket socket = socketHolder.getSocket()) {
                 this.inbuffer.clear();
                 this.outbuffer.flush(socketHolder.getOutputStream());
                 try {
@@ -246,8 +242,6 @@ class BHttpConnectionBase implements BHt
                 } catch (final UnsupportedOperationException ignore) {
                     // if one isn't supported, the other one isn't either
                 }
-            } finally {
-                socket.close();
             }
         }
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java?rev=1789732&r1=1789731&r2=1789732&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
Fri Mar 31 19:01:24 2017
@@ -148,9 +148,9 @@ public class DefaultBHttpClientConnectio
         if (len == ContentLengthStrategy.UNDEFINED) {
             throw new LengthRequiredException("Length required");
         }
-        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(),
entity.getTrailers());
-        entity.writeTo(outstream);
-        outstream.close();
+        try (final OutputStream outstream = createContentOutputStream(len, this.outbuffer,
socketHolder.getOutputStream(), entity.getTrailers())) {
+            entity.writeTo(outstream);
+        }
     }
 
     @Override
@@ -171,9 +171,9 @@ public class DefaultBHttpClientConnectio
             final OutputStream outstream = createContentOutputStream(len, this.outbuffer,
socketHolder.getOutputStream(), entity.getTrailers());
             outstream.close();
         } else if (len >= 0 && len <= 1024) {
-            final OutputStream outstream = createContentOutputStream(len, this.outbuffer,
socketHolder.getOutputStream(), null);
-            entity.writeTo(outstream);
-            outstream.close();
+            try (final OutputStream outstream = createContentOutputStream(len, this.outbuffer,
socketHolder.getOutputStream(), null)) {
+                entity.writeTo(outstream);
+            }
         } else {
             this.consistent = false;
         }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java?rev=1789732&r1=1789731&r2=1789732&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
Fri Mar 31 19:01:24 2017
@@ -172,8 +172,8 @@ public class DefaultBHttpServerConnectio
             return;
         }
         final long len = this.outgoingContentStrategy.determineLength(response);
-        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(),
entity.getTrailers());
-        entity.writeTo(outstream);
-        outstream.close();
+        try (final OutputStream outstream = createContentOutputStream(len, this.outbuffer,
socketHolder.getOutputStream(), entity.getTrailers())) {
+            entity.writeTo(outstream);
+        }
     }
 }



Mime
View raw message