You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/08/03 12:10:04 UTC
[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 <gi...@apache.org>
Authored: Fri Aug 3 13:54:24 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
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");
}