cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/3] cxf git commit: More stream closing
Date Fri, 22 Apr 2016 15:44:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes c4a261b1b -> 438919fe6


More stream closing


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

Branch: refs/heads/3.1.x-fixes
Commit: 96925fbbacc92c576743251f120d88ebde505556
Parents: c4a261b
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Apr 22 12:13:10 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Apr 22 15:44:29 2016 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/javascript/JsHttpRequestTest.java     | 10 ++--------
 .../apache/cxf/rs/security/jose/common/JoseUtils.java    |  5 +++--
 .../transport/http_jetty/JettyHTTPServerEngineTest.java  |  7 ++++---
 .../cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java | 11 +++++++----
 .../org/apache/cxf/systest/servlet/JaxRsServletTest.java |  9 ++-------
 5 files changed, 18 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/96925fbb/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
----------------------------------------------------------------------
diff --git a/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
b/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
index b2055a0..5e8b983 100644
--- a/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
+++ b/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
@@ -21,7 +21,6 @@ package org.apache.cxf.javascript;
 
 import java.io.File;
 import java.io.Reader;
-import java.io.StringWriter;
 import java.net.URL;
 import java.util.Properties;
 
@@ -31,6 +30,7 @@ import javax.xml.xpath.XPathConstants;
 import org.w3c.dom.Document;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier;
 import org.apache.cxf.jaxws.EndpointImpl;
 import org.apache.cxf.test.AbstractCXFSpringTest;
@@ -114,13 +114,7 @@ public class JsHttpRequestTest extends AbstractCXFSpringTest {
         // check for 'Shalom' in Hebrew as a charset check.
         assertTrue(httpResponse.contains("\u05e9\u05dc\u05d5\u05dd"));
         Reader r = getResourceAsReader("/org/apache/cxf/javascript/XML_GreetMeDocLiteralReq.xml");
-        StringWriter writer = new StringWriter();
-        char[] buffer = new char[1024];
-        int readCount;
-        while ((readCount = r.read(buffer, 0, 1024)) > 0) {
-            writer.write(buffer, 0, readCount);
-        }
-        String xml = writer.toString();
+        String xml = IOUtils.toString(r);
         EndpointImpl endpoint = this.getBean(EndpointImpl.class, "greeter-service-endpoint");
         JsSimpleDomNode xmlResponse = 
             testUtilities.rhinoCallConvert("testSyncXml", 

http://git-wip-us.apache.org/repos/asf/cxf/blob/96925fbb/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/common/JoseUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/common/JoseUtils.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/common/JoseUtils.java
index 225540e..12741c8 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/common/JoseUtils.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/common/JoseUtils.java
@@ -195,8 +195,9 @@ public final class JoseUtils {
     
     public static Properties loadProperties(String propertiesLocation, Bus bus) throws Exception
{
         Properties props = new Properties();
-        InputStream is = getResourceStream(propertiesLocation, bus);
-        props.load(is);
+        try (InputStream is = getResourceStream(propertiesLocation, bus)) {
+            props.load(is);
+        }
         return props;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/96925fbb/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
index 704a149..778c77b 100644
--- a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
+++ b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
@@ -416,8 +416,9 @@ public class JettyHTTPServerEngineTest extends Assert {
         assertTrue(connection instanceof HttpURLConnection);
         connection.connect();
         InputStream in = connection.getInputStream();
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        IOUtils.copy(in, buffer);
-        return buffer.toString();
+        try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
+            IOUtils.copy(in, buffer);
+            return buffer.toString();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/96925fbb/services/xkms/xkms-x509-repo-ldap/src/test/java/org/apache/cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java
----------------------------------------------------------------------
diff --git a/services/xkms/xkms-x509-repo-ldap/src/test/java/org/apache/cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java
b/services/xkms/xkms-x509-repo-ldap/src/test/java/org/apache/cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java
index 167eb0c..17dc53f 100644
--- a/services/xkms/xkms-x509-repo-ldap/src/test/java/org/apache/cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java
+++ b/services/xkms/xkms-x509-repo-ldap/src/test/java/org/apache/cxf/xkms/x509/repo/ldap/LDAPCertificateRepoTest.java
@@ -21,6 +21,7 @@ package org.apache.cxf.xkms.x509.repo.ldap;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
@@ -83,6 +84,7 @@ public class LDAPCertificateRepoTest {
         FileInputStream fis = new FileInputStream(certFile);
         CertificateFactory factory = CertificateFactory.getInstance("X.509");
         X509Certificate cert = (X509Certificate) factory.generateCertificate(fis);
+        fis.close();
 
         UseKeyWithType key = new UseKeyWithType();
         key.setApplication(Applications.PKIX.getUri());
@@ -136,11 +138,12 @@ public class LDAPCertificateRepoTest {
         c.verify();
     }
 
-    private X509Certificate getTestCert() throws FileNotFoundException, CertificateException
{
+    private X509Certificate getTestCert() throws FileNotFoundException, CertificateException,
IOException {
         File certFile = new File("src/test/resources/cert1.cer");
         Assert.assertTrue(certFile.exists());
-        FileInputStream fis = new FileInputStream(certFile);
-        CertificateFactory factory = CertificateFactory.getInstance("X.509");
-        return (X509Certificate) factory.generateCertificate(fis);
+        try (FileInputStream fis = new FileInputStream(certFile)) {
+            CertificateFactory factory = CertificateFactory.getInstance("X.509");
+            return (X509Certificate) factory.generateCertificate(fis);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/96925fbb/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
index e4a3b7e..a3dbd8a 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
@@ -27,7 +27,6 @@ import com.meterware.servletunit.ServletUnitClient;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CachedOutputStream;
 
 import org.junit.Test;
 
@@ -71,11 +70,7 @@ public class JaxRsServletTest extends AbstractServletTest {
      
     }
     
-    private String getStringFromInputStream(InputStream in) throws Exception {        
-        CachedOutputStream bos = new CachedOutputStream();
-        IOUtils.copy(in, bos);
-        in.close();
-        bos.close();            
-        return bos.getOut().toString();        
+    private String getStringFromInputStream(InputStream in) throws Exception {
+        return IOUtils.toString(in);
     }
 }


Mime
View raw message