Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F09601890D for ; Wed, 27 Jan 2016 08:27:47 +0000 (UTC) Received: (qmail 88234 invoked by uid 500); 27 Jan 2016 08:27:41 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 88194 invoked by uid 500); 27 Jan 2016 08:27:41 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 88185 invoked by uid 99); 27 Jan 2016 08:27:41 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jan 2016 08:27:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 445F7C27D3 for ; Wed, 27 Jan 2016 08:27:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.799 X-Spam-Level: * X-Spam-Status: No, score=1.799 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id lkx6cKjeNfnh for ; Wed, 27 Jan 2016 08:27:40 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 45DED24E24 for ; Wed, 27 Jan 2016 08:27:39 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 417DDE050C for ; Wed, 27 Jan 2016 08:27:38 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 409153A1751 for ; Wed, 27 Jan 2016 08:27:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1726955 - in /httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl: auth/BasicAuthCache.java auth/DigestScheme.java sync/CloseableHttpClient.java Date: Wed, 27 Jan 2016 08:27:38 -0000 To: commits@hc.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160127082738.409153A1751@svn01-us-west.apache.org> Author: ggregory Date: Wed Jan 27 08:27:37 2016 New Revision: 1726955 URL: http://svn.apache.org/viewvc?rev=1726955&view=rev Log: Use Java 7's try-with-resources. Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java?rev=1726955&r1=1726954&r2=1726955&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java (original) +++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java Wed Jan 27 08:27:37 2016 @@ -102,9 +102,9 @@ public class BasicAuthCache implements A if (authScheme instanceof Serializable) { try { final ByteArrayOutputStream buf = new ByteArrayOutputStream(); - final ObjectOutputStream out = new ObjectOutputStream(buf); - out.writeObject(authScheme); - out.close(); + try (final ObjectOutputStream out = new ObjectOutputStream(buf)) { + out.writeObject(authScheme); + } this.map.put(getKey(host), buf.toByteArray()); } catch (IOException ex) { if (log.isWarnEnabled()) { @@ -125,10 +125,9 @@ public class BasicAuthCache implements A if (bytes != null) { try { final ByteArrayInputStream buf = new ByteArrayInputStream(bytes); - final ObjectInputStream in = new ObjectInputStream(buf); - final AuthScheme authScheme = (AuthScheme) in.readObject(); - in.close(); - return authScheme; + try (final ObjectInputStream in = new ObjectInputStream(buf)) { + return (AuthScheme) in.readObject(); + } } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Unexpected I/O error while de-serializing auth scheme", ex); Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java?rev=1726955&r1=1726954&r2=1726955&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java (original) +++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java Wed Jan 27 08:27:37 2016 @@ -279,9 +279,9 @@ public class DigestScheme implements Aut } final StringBuilder sb = new StringBuilder(8); - final Formatter formatter = new Formatter(sb, Locale.US); - formatter.format("%08x", nounceCount); - formatter.close(); + try (final Formatter formatter = new Formatter(sb, Locale.US)) { + formatter.format("%08x", nounceCount); + } final String nc = sb.toString(); if (cnonce == null) { Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java?rev=1726955&r1=1726954&r2=1726955&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java (original) +++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java Wed Jan 27 08:27:37 2016 @@ -211,29 +211,27 @@ public abstract class CloseableHttpClien */ @Override public T execute(final HttpHost target, final HttpRequest request, - final ResponseHandler responseHandler, final HttpContext context) - throws IOException { + final ResponseHandler responseHandler, final HttpContext context) throws IOException { Args.notNull(responseHandler, "Response handler"); - final CloseableHttpResponse response = execute(target, request, context); - try { - final T result = responseHandler.handleResponse(response); - final HttpEntity entity = response.getEntity(); - EntityUtils.consume(entity); - return result; - } catch (final ClientProtocolException t) { - // Try to salvage the underlying connection in case of a protocol exception - final HttpEntity entity = response.getEntity(); + try (final CloseableHttpResponse response = execute(target, request, context)) { try { + final T result = responseHandler.handleResponse(response); + final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); - } catch (final Exception t2) { - // Log this exception. The original exception is more - // important and will be thrown to the caller. - this.log.warn("Error consuming content after an exception.", t2); + return result; + } catch (final ClientProtocolException t) { + // Try to salvage the underlying connection in case of a protocol exception + final HttpEntity entity = response.getEntity(); + try { + EntityUtils.consume(entity); + } catch (final Exception t2) { + // Log this exception. The original exception is more + // important and will be thrown to the caller. + this.log.warn("Error consuming content after an exception.", t2); + } + throw t; } - throw t; - } finally { - response.close(); } }