From notifications-return-31821-archive-asf-public=cust-asf.ponee.io@ant.apache.org Fri Aug 3 14:10:04 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id AED9718072F for ; Fri, 3 Aug 2018 14:10:03 +0200 (CEST) Received: (qmail 43214 invoked by uid 500); 3 Aug 2018 12:10:02 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 43092 invoked by uid 99); 3 Aug 2018 12:10:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Aug 2018 12:10:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 23DBEE0A4E; Fri, 3 Aug 2018 12:10:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gintas@apache.org To: notifications@ant.apache.org Date: Fri, 03 Aug 2018 12:10:04 -0000 Message-Id: <7350c7ea77354457bf0abbd01a2b8455@git.apache.org> In-Reply-To: <2c1047d2198d440b9dd249be1b32bdf5@git.apache.org> References: <2c1047d2198d440b9dd249be1b32bdf5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/5] ant-ivy git commit: Use try with resources Use try with resources Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/93f11da8 Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/93f11da8 Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/93f11da8 Branch: refs/heads/master Commit: 93f11da846cb97cd940de5826925fe15b1200e94 Parents: b5b177b Author: Gintas Grigelionis Authored: Fri Aug 3 13:54:24 2018 +0200 Committer: Gintas Grigelionis Committed: Fri Aug 3 13:54:24 2018 +0200 ---------------------------------------------------------------------- src/java/org/apache/ivy/ant/IvyReport.java | 22 ++-------------------- test/java/org/apache/ivy/TestHelper.java | 12 +----------- 2 files changed, 3 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/93f11da8/src/java/org/apache/ivy/ant/IvyReport.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/ant/IvyReport.java b/src/java/org/apache/ivy/ant/IvyReport.java index 62217d5..cfac8df 100644 --- a/src/java/org/apache/ivy/ant/IvyReport.java +++ b/src/java/org/apache/ivy/ant/IvyReport.java @@ -341,31 +341,13 @@ public class IvyReport extends IvyTask { } } - InputStream inStream = null; - OutputStream outStream = null; - try { - inStream = new BufferedInputStream(new FileInputStream(reportFile)); - outStream = new BufferedOutputStream(new FileOutputStream(outFile)); + try (InputStream inStream = new BufferedInputStream(new FileInputStream(reportFile)); + OutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile))) { StreamResult res = new StreamResult(outStream); Source src = new StreamSource(inStream, JAXPUtils.getSystemId(style)); transformer.transform(src, res); } catch (TransformerException e) { throw new BuildException(e); - } finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - // ignore - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - // ignore - } - } } } } catch (TransformerConfigurationException e) { http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/93f11da8/test/java/org/apache/ivy/TestHelper.java ---------------------------------------------------------------------- diff --git a/test/java/org/apache/ivy/TestHelper.java b/test/java/org/apache/ivy/TestHelper.java index 5ffe8ac..066e419 100644 --- a/test/java/org/apache/ivy/TestHelper.java +++ b/test/java/org/apache/ivy/TestHelper.java @@ -497,9 +497,7 @@ public class TestHelper { * after this method since the associated socket is released and some other process can now use it. */ public static int getMaybeAvailablePort() { - ServerSocket s = null; - try { - s = new ServerSocket(0); + try (ServerSocket s = new ServerSocket(0)) { s.setReuseAddress(true); int port = s.getLocalPort(); try { @@ -510,14 +508,6 @@ public class TestHelper { return port; } catch (IOException e) { // ignore - } finally { - if (s != null) { - try { - s.close(); - } catch (IOException e) { - // ignore - } - } } throw new IllegalStateException("Not TCP/IP port available"); }