cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: More try with resources work
Date Wed, 25 Feb 2015 10:57:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3ae567d26 -> 85fdb62d0


More try with resources work


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/85fdb62d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/85fdb62d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/85fdb62d

Branch: refs/heads/master
Commit: 85fdb62d0a3bb7c2e1616702204c2bc33f7356e4
Parents: 3ae567d
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Feb 25 10:56:41 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Feb 25 10:56:41 2015 +0000

----------------------------------------------------------------------
 .../maven_plugin/wsdl2java/WSDL2JavaMojo.java   |  8 +----
 .../cxf/maven_plugin/WSDLValidatorMojo.java     |  8 +----
 .../cxf/osgi/itests/CXFOSGiTestSupport.java     |  8 +----
 ...entServerResourceCreatedOutsideBookTest.java |  5 +--
 ...ServerResourceCreatedSpringProviderTest.java |  5 +--
 .../systest/kerberos/ldap/LDAPClaimsTest.java   |  8 +----
 .../jaxrs/security/oauth/OAuthTestUtils.java    | 22 +++++---------
 .../systest/schemaimport/SchemaImportTest.java  | 32 +++-----------------
 8 files changed, 17 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
index a99b988..22eea50 100644
--- a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
+++ b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
@@ -265,15 +265,9 @@ public class WSDL2JavaMojo extends AbstractCodegenMoho {
         doneFile.createNewFile();
         URI basedir = project.getBasedir().toURI();
         String options = wsdlOption.generateCommandLine(null, basedir, wsdlURI, false).toString();
-        DataOutputStream writer = null;
-        try {
-            writer = new DataOutputStream(new FileOutputStream(doneFile));
+        try (DataOutputStream writer = new DataOutputStream(new FileOutputStream(doneFile)))
{
             writer.writeUTF(options);
             writer.flush();
-        } finally {
-            if (writer != null) {
-                writer.close();
-            }
         }
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
b/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
index 49ffc19..ed8807d 100644
--- a/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
+++ b/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
@@ -147,14 +147,8 @@ public class WSDLValidatorMojo extends AbstractMojo {
                 String[] pargs = list.toArray(new String[list.size()]);
                 
                 ToolSpec spec = null;
-                InputStream toolspecStream = null;
-                try {
-                    toolspecStream = WSDLValidator.class .getResourceAsStream("wsdlvalidator.xml");
+                try (InputStream toolspecStream = WSDLValidator.class .getResourceAsStream("wsdlvalidator.xml"))
{
                     spec = new ToolSpec(toolspecStream, false);
-                } finally {
-                    if (toolspecStream != null) {
-                        toolspecStream.close();
-                    }
                 }
                 WSDLValidator validator = new WSDLValidator(spec);
                 validator.setArguments(pargs);

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
----------------------------------------------------------------------
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
index cca96df..138b996 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
@@ -340,20 +340,14 @@ public class CXFOSGiTestSupport {
      */
     public static boolean isPortAvailable(int port) {
         ServerSocket ss = null;
-        DatagramSocket ds = null;
-        try {
+        try (DatagramSocket ds = new DatagramSocket(port)) {
             ss = new ServerSocket(port);
             ss.setReuseAddress(true);
-            ds = new DatagramSocket(port);
             ds.setReuseAddress(true);
             return true;
         } catch (IOException e) {
             // ignore
         } finally {
-            if (ds != null) {
-                ds.close();
-            }
-
             if (ss != null) {
                 try {
                     ss.close();

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
index 8f04353..77b30b8 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
@@ -86,13 +86,10 @@ public class JAXRSClientServerResourceCreatedOutsideBookTest extends AbstractBus
          
         byte[] tmp = new byte[4096];
         int i = 0;
-        InputStream is = new FileInputStream(inputFile);
-        try {
+        try (InputStream is = new FileInputStream(inputFile)) {
             while ((i = is.read(tmp)) >= 0) {
                 outputstream.write(tmp, 0, i);
             }
-        } finally {
-            is.close();
         }
 
         outputstream.flush();

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
index 48f526c..1ccd4e9 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
@@ -294,13 +294,10 @@ public class JAXRSClientServerResourceCreatedSpringProviderTest extends
Abstract
          
         byte[] tmp = new byte[4096];
         int i = 0;
-        InputStream is = new FileInputStream(inputFile);
-        try {
+        try (InputStream is = new FileInputStream(inputFile)) {
             while ((i = is.read(tmp)) >= 0) {
                 outputstream.write(tmp, 0, i);
             }
-        } finally {
-            is.close();
         }
 
         outputstream.flush();

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
----------------------------------------------------------------------
diff --git a/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
b/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
index 4fdbfff..04347ee 100644
--- a/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
+++ b/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
@@ -93,16 +93,10 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     public static void startServers() throws Exception {
         props = new Properties();
 
-        InputStream is = null;
-        try {
-            is = LDAPClaimsTest.class.getResourceAsStream("/ldap.properties");
+        try (InputStream is = LDAPClaimsTest.class.getResourceAsStream("/ldap.properties"))
{
             props.load(is);
         } catch (Exception e) {
             e.printStackTrace();
-        } finally {
-            if (is != null) {
-                is.close();
-            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java
index 68ffac0..26f4adb 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java
@@ -66,25 +66,17 @@ public final class OAuthTestUtils {
 
     public static String readBody(OAuthMessage msg) throws IOException {
         StringBuilder body = new StringBuilder();
-        InputStream responseBody = null;
-        BufferedReader br = null;
-        try {
-            responseBody = msg.getBodyAsStream();
+        try (InputStream responseBody = msg.getBodyAsStream()) {
             if (responseBody != null) {
-                br = new BufferedReader(new InputStreamReader(responseBody));
-                String buf;
-                while ((buf = br.readLine()) != null) {
-                    body.append(buf);
+                try (BufferedReader br = new BufferedReader(new InputStreamReader(responseBody)))
{
+                    String buf;
+                    while ((buf = br.readLine()) != null) {
+                        body.append(buf);
+                    }
                 }
             }
-        } finally {
-            if (br != null) {
-                br.close();
-            }
-            if (responseBody != null) {
-                responseBody.close();
-            }
         }
+
         return body.toString().trim();
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/85fdb62d/systests/uncategorized/src/test/java/org/apache/cxf/systest/schemaimport/SchemaImportTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schemaimport/SchemaImportTest.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schemaimport/SchemaImportTest.java
index 1428b18..b73ff93 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schemaimport/SchemaImportTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schemaimport/SchemaImportTest.java
@@ -39,18 +39,12 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase
{
     public void testImportSchema() throws Exception {
         String schemaURL = "http://localhost:" + PORT + "/schemaimport/sayHi" + "?xsd=sayhi/sayhi/sayhi-schema1.xsd";
         URL url = new URL(schemaURL);
-        InputStream ins = null;
-        try {
-            ins = url.openStream();
+        try (InputStream ins = url.openStream()) {
             String output = IOUtils.toString(ins);
             assertTrue(output.indexOf("sayHiArray") > -1);
         } catch (Exception e) {
             e.printStackTrace();
             fail("Can not access the import schema");
-        } finally {
-            if (ins != null) {
-                ins.close();
-            }
         }
     }
 
@@ -58,19 +52,13 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase
{
     public void testImportWsdl() throws Exception {
         String wsdlURL = "http://localhost:" + PORT + "/schemaimport/sayHi"  + "?wsdl=sayhi/sayhi/a.wsdl";
         URL url = new URL(wsdlURL);
-        InputStream ins = null;
-        try {
-            ins = url.openStream();
+        try (InputStream ins = url.openStream()) {
             String output = IOUtils.toString(ins);
             assertTrue(output.indexOf("sayHiArray") > -1);
         } catch (Exception e) {
             e.printStackTrace();
             fail("Can not access the import wsdl");
 
-        } finally {
-            if (ins != null) {
-                ins.close();
-            }
         }
     }
     
@@ -79,9 +67,7 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase {
     public void testAnotherSchemaImportl() throws Exception {
         String schemaURL = "http://localhost:" + PORT + "/schemaimport/service"  + "?xsd=schema1.xsd";
         URL url = new URL(schemaURL);
-        InputStream ins = null;
-        try {
-            ins = url.openStream();
+        try (InputStream ins = url.openStream()) {
             String output = IOUtils.toString(ins);
             assertTrue(output.indexOf("schemaimport/service?xsd=schema2.xsd") > -1);
             assertTrue(output.indexOf("schemaimport/service?xsd=schema5.xsd") > -1);
@@ -89,10 +75,6 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase {
             e.printStackTrace();
             fail("Can not access the import wsdl");
 
-        } finally {
-            if (ins != null) {
-                ins.close();
-            }
         }
     }
     
@@ -101,9 +83,7 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase {
     public void testSchemaInclude() throws Exception {
         String schemaURL = "http://localhost:" + PORT + "/schemainclude/service?xsd=d1/d1/test.xsd";
         URL url = new URL(schemaURL);
-        InputStream ins = null;
-        try {
-            ins = url.openStream();
+        try (InputStream ins = url.openStream()) {
             String output = IOUtils.toString(ins);
             assertTrue(output.indexOf("msg:RequestType") > -1);
             assertTrue(output.indexOf("msg:SomeFeatureType") > -1);
@@ -111,10 +91,6 @@ public class SchemaImportTest extends AbstractBusClientServerTestBase
{
             e.printStackTrace();
             fail("Can not access the include schema");
 
-        } finally {
-            if (ins != null) {
-                ins.close();
-            }
         }
     }
 


Mime
View raw message