[jboss-cvs] JBossAS SVN: r68748 - branches/Branch_4_2/webservices/src/main/org/jboss/wsf/container/jboss42.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 9 15:24:06 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-01-09 15:24:06 -0500 (Wed, 09 Jan 2008)
New Revision: 68748

Modified:
   branches/Branch_4_2/webservices/src/main/org/jboss/wsf/container/jboss42/WebXMLRewriterImpl.java
Log:
Fix JBAS-5112: WebXMLRewriter leaks input stream

Modified: branches/Branch_4_2/webservices/src/main/org/jboss/wsf/container/jboss42/WebXMLRewriterImpl.java
===================================================================
--- branches/Branch_4_2/webservices/src/main/org/jboss/wsf/container/jboss42/WebXMLRewriterImpl.java	2008-01-09 20:22:38 UTC (rev 68747)
+++ branches/Branch_4_2/webservices/src/main/org/jboss/wsf/container/jboss42/WebXMLRewriterImpl.java	2008-01-09 20:24:06 UTC (rev 68748)
@@ -83,8 +83,7 @@
          if (webXML.renameTo(orgWebXML) == false)
             throw new WebServiceException("Cannot rename web.xml: " + orgWebXML);
 
-         FileInputStream stream = new FileInputStream(orgWebXML);
-         return rewriteWebXml(stream, webXML, dep);
+         return rewriteWebXml(orgWebXML, webXML, dep);
       }
       catch (RuntimeException rte)
       {
@@ -96,7 +95,7 @@
       }
    }
 
-   private RewriteResults rewriteWebXml(InputStream source, File destFile, Deployment dep) throws Exception
+   private RewriteResults rewriteWebXml(File input, File destFile, Deployment dep) throws Exception
    {
       if (destFile == null)
       {
@@ -104,18 +103,33 @@
          destFile.deleteOnExit();
       }
 
-      SAXReader reader = new SAXReader();
-      Document document = reader.read(source);
+      FileInputStream inputStream = null;
+      FileOutputStream outputStream = null;
 
-      RewriteResults results = desciptorModifier.modifyDescriptor(dep, document);
-      results.webXML = destFile.toURL();
+      try
+      {
+         inputStream = new FileInputStream(input);
+         SAXReader reader = new SAXReader();
+         Document document = reader.read(inputStream);
 
-      FileOutputStream fos = new FileOutputStream(destFile);
-      OutputFormat format = OutputFormat.createPrettyPrint();
-      XMLWriter writer = new XMLWriter(fos, format);
-      writer.write(document);
-      writer.close();
+         RewriteResults results = desciptorModifier.modifyDescriptor(dep, document);
+         results.webXML = destFile.toURL();
 
-      return results;
+         outputStream = new FileOutputStream(destFile);
+         OutputFormat format = OutputFormat.createPrettyPrint();
+         XMLWriter writer = new XMLWriter(outputStream, format);
+         writer.write(document);
+         writer.close();
+
+         return results;
+      }
+      finally
+      {
+         if(inputStream!=null)
+            inputStream.close();
+
+         if(outputStream!=null)
+            outputStream.close();
+      }
    }
 }




More information about the jboss-cvs-commits mailing list