8067183: TEST_BUG:File locked when processing the cleanup on test jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java
authorjoehw
Wed, 10 Dec 2014 16:38:01 -0800
changeset 27981 52d636dec3f2
parent 27862 3107be2ba9c6
child 27982 3cafd24fcc3e
8067183: TEST_BUG:File locked when processing the cleanup on test jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java Reviewed-by: joehw Contributed-by: tristan.yan@oracle.com
jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java	Wed Jul 05 20:10:08 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java	Wed Dec 10 16:38:01 2014 -0800
@@ -61,33 +61,25 @@
         String xmlFile = XML_DIR + "TransformerFactoryTest.xml";
         String xmlURI = "file:///" + XML_DIR;
 
-        try {
+        try (FileInputStream fis = new FileInputStream(xmlFile);
+                FileOutputStream fos = new FileOutputStream(outputFile);) {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 
             DocumentBuilder db = dbf.newDocumentBuilder();
-            Document doc = db.parse(new FileInputStream(xmlFile), xmlURI);
+            Document doc = db.parse(fis, xmlURI);
             DOMSource domSource = new DOMSource(doc);
             domSource.setSystemId(xmlURI);
-            StreamResult streamResult =new StreamResult(
-                new FileOutputStream(outputFile));
+            StreamResult streamResult = new StreamResult(fos);
             TransformerFactory tFactory = TransformerFactory.newInstance();
 
-            Source s = tFactory.getAssociatedStylesheet(domSource,"screen",
-                                           "Modern",null);
+            Source s = tFactory.getAssociatedStylesheet(domSource, "screen",
+                                           "Modern", null);
             Transformer t = tFactory.newTransformer();
-            t.transform(s,streamResult);
+            t.transform(s, streamResult);
             assertTrue(compareWithGold(goldFile, outputFile));
-        }catch (IOException | ParserConfigurationException
+        } catch (IOException | ParserConfigurationException
                 | TransformerException | SAXException ex) {
             failUnexpected(ex);
-        } finally {
-            try {
-                Path outputPath = Paths.get(outputFile);
-                if(Files.exists(outputPath))
-                    Files.delete(outputPath);
-            } catch (IOException ex) {
-                failCleanup(ex, outputFile);
-            }
         }
     }
 }