Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4A00F19E4C for ; Fri, 22 Apr 2016 02:13:11 +0000 (UTC) Received: (qmail 49627 invoked by uid 500); 22 Apr 2016 02:13:10 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 49295 invoked by uid 500); 22 Apr 2016 02:13:10 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 48812 invoked by uid 99); 22 Apr 2016 02:13:10 -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, 22 Apr 2016 02:13:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EC336E0BAC; Fri, 22 Apr 2016 02:13:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: reta@apache.org To: commits@cxf.apache.org Date: Fri, 22 Apr 2016 02:13:15 -0000 Message-Id: <5acbe5e27782438b9aae779229d6d65e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/21] cxf git commit: More stream closing 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 Authored: Wed Apr 20 12:55:58 2016 +0100 Committer: Colm O hEigeartaigh 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 { 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 "