archiva-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joakim Erdfelt <joa...@erdfelt.com>
Subject Re: svn commit: r578266 - in /maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml: XMLReader.java XMLWriter.java
Date Tue, 09 Oct 2007 15:48:57 GMT
The writer method doesn't close the stream anymore.
It was fixed about 10 minutes after that commit in revision 578279

- Joakim

Brett Porter wrote:
> Joakim?
>
> On 22/09/2007, at 1:32 AM, Brett Porter wrote:
>
>> Joakim,
>>
>> Are you sure about the second one? If the writer is passed in to the 
>> method, I would expect the caller to close the writer, not the method 
>> itself (I'm not sure whether the xmlwriter closes it's underlying 
>> writer or not, though, but think it's worth checking).
>>
>> - Brett
>>
>> On 22/09/2007, at 6:46 AM, joakime@apache.org wrote:
>>
>>> Author: joakime
>>> Date: Fri Sep 21 13:46:15 2007
>>> New Revision: 578266
>>>
>>> URL: http://svn.apache.org/viewvc?rev=578266&view=rev
>>> Log:
>>> [MRM-243] 507 Insufficient Storage when deploying artifact with webdav
>>> Adding proper IO closures to opened XML files.
>>>
>>> Modified:
>>>     
>>> maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLReader.java

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

>>>
>>>
>>> Modified: 
>>> maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLReader.java

>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLReader.java?rev=578266&r1=578265&r2=578266&view=diff

>>>
>>> ==============================================================================

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

>>> (original)
>>> +++ 
>>> maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLReader.java

>>> Fri Sep 21 13:46:15 2007
>>> @@ -19,6 +19,7 @@
>>>   * 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 @@
>>>
>>>      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 @@
>>>          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 @@
>>>          {
>>>              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 @@
>>>
>>>          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 List getElementList( String xpathExpr )
>>> +    public List<Element> getElementList( String xpathExpr )
>>>          throws XMLException
>>>      {
>>>          XPath xpath = createXPath( xpathExpr );
>>> @@ -287,12 +294,12 @@
>>>
>>>          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 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;
>>>
>>> Modified: 
>>> maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLWriter.java

>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLWriter.java?rev=578266&r1=578265&r2=578266&view=diff

>>>
>>> ==============================================================================

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

>>> (original)
>>> +++ 
>>> maven/archiva/trunk/archiva-base/archiva-xml-tools/src/main/java/org/apache/maven/archiva/xml/XMLWriter.java

>>> Fri Sep 21 13:46:15 2007
>>> @@ -36,16 +36,32 @@
>>>      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();
>>>          }
>>>          catch ( IOException e )
>>>          {
>>>              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 */
>>> +                }
>>> +            }
>>>          }
>>>      }
>>>  }
>>>
>>
>> -- 
>> Brett Porter - brett@apache.org
>> Blog: http://www.devzuz.org/blogs/bporter/
>
> -- 
> Brett Porter - brett@apache.org
> Blog: http://www.devzuz.org/blogs/bporter/
>


-- 
- Joakim Erdfelt
  joakim@erdfelt.com
  Open Source Software (OSS) Developer


Mime
View raw message