cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [07/21] cxf git commit: More stream closing
Date Fri, 22 Apr 2016 02:13:15 GMT
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/ea6a524a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ea6a524a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ea6a524a

Branch: refs/heads/master-jaxrs-2.1
Commit: ea6a524acaba5005c5794d3be5c4342134ea37ea
Parents: 41231ee
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Apr 20 12:55:58 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Apr 20 12:55:58 2016 +0100

----------------------------------------------------------------------
 .../x509/repo/file/FileCertificateRepo.java     | 36 +++++++++++---------
 .../x509/repo/file/FileCertificateRepoTest.java | 17 ++++-----
 .../provider/HWSAXSourcePayloadProvider.java    | 11 +++---
 .../apache/cxf/tools/corba/IDLToWSDLTest.java   | 17 ++++-----
 4 files changed, 44 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ea6a524a/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepo.java
----------------------------------------------------------------------
diff --git a/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepo.java
b/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepo.java
index ef250e9..1c6db39 100644
--- a/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepo.java
+++ b/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepo.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.math.BigInteger;
 import java.net.URISyntaxException;
 import java.security.cert.CRLException;
@@ -86,11 +87,11 @@ public class FileCertificateRepo implements CertificateRepo {
             
             File certFile = new File(storageDir + "/" + CRLS_PATH, path);
             certFile.getParentFile().mkdirs();
-            FileOutputStream fos = new FileOutputStream(certFile);
-            BufferedOutputStream bos = new BufferedOutputStream(fos);
-            bos.write(crl.getEncoded());
-            bos.close();
-            fos.close();
+            try (FileOutputStream fos = new FileOutputStream(certFile);
+                BufferedOutputStream bos = new BufferedOutputStream(fos)) {
+                bos.write(crl.getEncoded());
+                bos.close();
+            }
         } catch (Exception e) {
             throw new RuntimeException("Error saving CRL " + name + ": " + e.getMessage(),
e);
         }
@@ -109,11 +110,11 @@ public class FileCertificateRepo implements CertificateRepo {
             File certFile = new File(storageDir + "/" + category,
                                      getCertPath(cert, id));
             certFile.getParentFile().mkdirs();
-            FileOutputStream fos = new FileOutputStream(certFile);
-            BufferedOutputStream bos = new BufferedOutputStream(fos);
-            bos.write(cert.getEncoded());
-            bos.close();
-            fos.close();
+            try (FileOutputStream fos = new FileOutputStream(certFile);
+                BufferedOutputStream bos = new BufferedOutputStream(fos)) {
+                bos.write(cert.getEncoded());
+                bos.close();
+            }
         } catch (Exception e) {
             throw new RuntimeException("Error saving certificate " + cert.getSubjectDN()
+ ": " + e.getMessage(), e);
         }
@@ -175,14 +176,17 @@ public class FileCertificateRepo implements CertificateRepo {
         return certificateFiles.toArray(new File[certificateFiles.size()]);
     }
 
-    public X509Certificate readCertificate(File certFile) throws CertificateException, FileNotFoundException
{
-        FileInputStream fis = new FileInputStream(certFile);
-        return (X509Certificate)certFactory.generateCertificate(fis);
+    public X509Certificate readCertificate(File certFile) throws CertificateException, FileNotFoundException,
+        IOException {
+        try (FileInputStream fis = new FileInputStream(certFile)) {
+            return (X509Certificate)certFactory.generateCertificate(fis);
+        }
     }
     
-    public X509CRL readCRL(File crlFile) throws FileNotFoundException, CRLException {
-        FileInputStream fis = new FileInputStream(crlFile);
-        return (X509CRL)certFactory.generateCRL(fis);
+    public X509CRL readCRL(File crlFile) throws FileNotFoundException, CRLException, IOException
{
+        try (FileInputStream fis = new FileInputStream(crlFile)) {
+            return (X509CRL)certFactory.generateCRL(fis);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/ea6a524a/services/xkms/xkms-x509-handlers/src/test/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepoTest.java
----------------------------------------------------------------------
diff --git a/services/xkms/xkms-x509-handlers/src/test/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepoTest.java
b/services/xkms/xkms-x509-handlers/src/test/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepoTest.java
index d42b7c8..dff5317 100644
--- a/services/xkms/xkms-x509-handlers/src/test/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepoTest.java
+++ b/services/xkms/xkms-x509-handlers/src/test/java/org/apache/cxf/xkms/x509/repo/file/FileCertificateRepoTest.java
@@ -59,9 +59,10 @@ public class FileCertificateRepoTest {
 
         File certFile = new File(storageDir, fileRegisterHandler.getCertPath(cert, key));
         Assert.assertTrue("Cert file " + certFile + " should exist", certFile.exists());
-        FileInputStream fis = new FileInputStream(certFile);
-        X509Certificate outCert = loadTestCert(fis);
-        Assert.assertEquals(cert, outCert);
+        try (FileInputStream fis = new FileInputStream(certFile)) {
+            X509Certificate outCert = loadTestCert(fis);
+            Assert.assertEquals(cert, outCert);
+        }
 
         X509Certificate resultCert = fileRegisterHandler.findBySubjectDn(EXAMPLE_SUBJECT_DN);
         Assert.assertNotNull(resultCert);
@@ -93,11 +94,11 @@ public class FileCertificateRepoTest {
         is.close();
         byte[] certData = DatatypeConverter.parseBase64Binary(certString);
         File file = new File(destPath);
-        FileOutputStream fos = new FileOutputStream(file);
-        BufferedOutputStream bos = new BufferedOutputStream(fos);
-        bos.write(certData);
-        bos.close();
-        fos.close();
+        try (FileOutputStream fos = new FileOutputStream(file);
+            BufferedOutputStream bos = new BufferedOutputStream(fos)) {
+            bos.write(certData);
+            bos.close();
+        }
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/ea6a524a/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSAXSourcePayloadProvider.java
----------------------------------------------------------------------
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSAXSourcePayloadProvider.java
b/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSAXSourcePayloadProvider.java
index 01b151c..488a5a2 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSAXSourcePayloadProvider.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSAXSourcePayloadProvider.java
@@ -115,11 +115,12 @@ public class HWSAXSourcePayloadProvider implements Provider<SAXSource>
{
     
     private File getSOAPBodyFile(Document doc) throws Exception {
         File file = FileUtils.createTempFile("cxf-systest", "xml");
-        FileOutputStream out = new FileOutputStream(file);
-        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
-        StaxUtils.writeDocument(doc, writer, true);
-        writer.close();
-        return file;
+        try (FileOutputStream out = new FileOutputStream(file)) {
+            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
+            StaxUtils.writeDocument(doc, writer, true);
+            writer.close();
+            return file;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ea6a524a/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
----------------------------------------------------------------------
diff --git a/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java b/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
index 9dd6dbb..b3c72cc 100644
--- a/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
+++ b/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
@@ -192,15 +192,16 @@ public class IDLToWSDLTest extends ToolTestBase {
         File expectedWsdlFile = wsdlGenTester.writeDefinition(output, expected);
         File actualWsdlFile = wsdlGenTester.writeDefinition(output, actual);
 
-        InputStream actualFileStream = new FileInputStream(actualWsdlFile);
-        InputStream expectedFileStream = new FileInputStream(expectedWsdlFile);
+        try (InputStream actualFileStream = new FileInputStream(actualWsdlFile);
+            InputStream expectedFileStream = new FileInputStream(expectedWsdlFile)) {
         
-        XMLInputFactory factory = XMLInputFactory.newInstance();
-        
-        XMLStreamReader actualStream = factory.createXMLStreamReader(actualFileStream);
-        XMLStreamReader expectedStream = factory.createXMLStreamReader(expectedFileStream);
-        
-        wsdlGenTester.compare(expectedStream, actualStream);
+            XMLInputFactory factory = XMLInputFactory.newInstance();
+            
+            XMLStreamReader actualStream = factory.createXMLStreamReader(actualFileStream);
+            XMLStreamReader expectedStream = factory.createXMLStreamReader(expectedFileStream);
+            
+            wsdlGenTester.compare(expectedStream, actualStream);
+        }
     }
     
     // test "-x <schema-namespace>" 


Mime
View raw message