]> source.dussan.org Git - archiva.git/commitdiff
[MRM-243] 507 Insufficient Storage when deploying artifact with webdav
authorJoakim Erdfelt <joakime@apache.org>
Fri, 21 Sep 2007 20:46:15 +0000 (20:46 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Fri, 21 Sep 2007 20:46:15 +0000 (20:46 +0000)
Adding proper IO closures to opened XML files.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@578266 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLReader.java
archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLWriter.java

index 4abef4526db17b834bebe57298e9ac6a7c7762e8..f597499e80f232aa5759c1ceb6f7e12c142b1b3c 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.xml;
  * under the License.
  */
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -56,7 +57,7 @@ public class XMLReader
 
     private Document document;
 
-    private Map namespaceMap = new HashMap();
+    private Map<String, String> namespaceMap = new HashMap<String, String>();
 
     public XMLReader( String type, File file )
         throws XMLException
@@ -98,10 +99,12 @@ public class XMLReader
         this.documentType = type;
         this.xmlUrl = url;
 
+        InputStream in = null;
         SAXReader reader = new SAXReader();
+        
         try
         {
-            InputStream in = url.openStream();
+            in = url.openStream();
             InputStreamReader inReader = new InputStreamReader( in, "UTF-8" );
             LatinEntityResolutionReader latinReader = new LatinEntityResolutionReader( inReader );
             this.document = reader.read( latinReader );
@@ -114,6 +117,10 @@ public class XMLReader
         {
             throw new XMLException( "Unable to open stream to " + url + ": " + e.getMessage(), e );
         }
+        finally
+        {
+            IOUtils.closeQuietly( in );
+        }
 
         Element root = this.document.getRootElement();
         if ( root == null )
@@ -204,10 +211,10 @@ public class XMLReader
 
         Node n;
 
-        Iterator it = elem.elementIterator();
+        Iterator<Node> it = elem.elementIterator();
         while ( it.hasNext() )
         {
-            n = (Node) it.next();
+            n = it.next();
 
             switch ( n.getNodeType() )
             {
@@ -269,7 +276,7 @@ public class XMLReader
         }
     }
 
-    public List getElementList( String xpathExpr )
+    public List<Element> getElementList( String xpathExpr )
         throws XMLException
     {
         XPath xpath = createXPath( xpathExpr );
@@ -287,12 +294,12 @@ public class XMLReader
 
         if ( evaluated instanceof List )
         {
-            return (List) evaluated;
+            return (List<Element>) evaluated;
         }
         else if ( evaluated instanceof Node )
         {
-            List ret = new ArrayList();
-            ret.add( evaluated );
+            List<Element> ret = new ArrayList<Element>();
+            ret.add( (Element) evaluated );
             return ret;
         }
         else
@@ -303,19 +310,19 @@ public class XMLReader
         }
     }
 
-    public List getElementListText( String xpathExpr )
+    public List<String> getElementListText( String xpathExpr )
         throws XMLException
     {
-        List elemList = getElementList( xpathExpr );
+        List<Element> elemList = getElementList( xpathExpr );
         if ( elemList == null )
         {
             return null;
         }
 
-        List ret = new ArrayList();
-        for ( Iterator iter = elemList.iterator(); iter.hasNext(); )
+        List<String> ret = new ArrayList<String>();
+        for ( Iterator<Element> iter = elemList.iterator(); iter.hasNext(); )
         {
-            Element listelem = (Element) iter.next();
+            Element listelem = iter.next();
             ret.add( listelem.getTextTrim() );
         }
         return ret;
index cbb6c7fee2d5fb1d1be7d1fe0543d3dc2bb53f58..f8f4acb7cf8a0dbdefbbabd32c9366258ff49c83 100644 (file)
@@ -36,10 +36,12 @@ public class XMLWriter
     public static void write( Document doc, Writer writer )
         throws XMLException
     {
+        org.dom4j.io.XMLWriter xmlwriter = null;
+        
         try
         {
             OutputFormat outputFormat = OutputFormat.createPrettyPrint();
-            org.dom4j.io.XMLWriter xmlwriter = new org.dom4j.io.XMLWriter( writer, outputFormat );
+            xmlwriter = new org.dom4j.io.XMLWriter( writer, outputFormat );
             xmlwriter.write( doc );
             xmlwriter.flush();
         }
@@ -47,5 +49,19 @@ public class XMLWriter
         {
             throw new XMLException( "Unable to write xml contents to writer: " + e.getMessage(), e );
         }
+        finally
+        {
+            if( xmlwriter != null )
+            {
+                try
+                {
+                    xmlwriter.close();
+                }
+                catch ( IOException e )
+                {
+                    /* quietly ignore */
+                }
+            }
+        }
     }
 }