Return-Path: Delivered-To: apmail-maven-archiva-dev-archive@locus.apache.org Received: (qmail 98189 invoked from network); 9 Oct 2007 15:25:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Oct 2007 15:25:24 -0000 Received: (qmail 19561 invoked by uid 500); 9 Oct 2007 15:11:38 -0000 Delivered-To: apmail-maven-archiva-dev-archive@maven.apache.org Received: (qmail 19529 invoked by uid 500); 9 Oct 2007 15:11:38 -0000 Mailing-List: contact archiva-dev-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: archiva-dev@maven.apache.org Delivered-To: mailing list archiva-dev@maven.apache.org Received: (qmail 19520 invoked by uid 99); 9 Oct 2007 15:11:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2007 08:11:38 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [210.50.30.235] (HELO mx05.syd.iprimus.net.au) (210.50.30.235) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2007 15:11:38 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAB83C0fZ5Iyc/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.21,249,1188741600"; d="scan'208";a="70816960" Received: from pd9e48c9c.dip0.t-ipconnect.de (HELO [192.168.2.110]) ([217.228.140.156]) by smtp05.syd.iprimus.net.au with ESMTP; 10 Oct 2007 01:11:12 +1000 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: References: <20070921204623.4B78A1A9832@eris.apache.org> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <6F7B77B3-AD7F-496E-BD07-BF618FE28C85@apache.org> Content-Transfer-Encoding: 7bit From: Brett Porter 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, 9 Oct 2007 17:11:08 +0200 To: archiva-dev@maven.apache.org X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org 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 namespaceMap = new >> HashMap(); >> >> 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 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 getElementList( String xpathExpr ) >> throws XMLException >> { >> XPath xpath = createXPath( xpathExpr ); >> @@ -287,12 +294,12 @@ >> >> if ( evaluated instanceof List ) >> { >> - return (List) evaluated; >> + return (List) evaluated; >> } >> else if ( evaluated instanceof Node ) >> { >> - List ret = new ArrayList(); >> - ret.add( evaluated ); >> + List ret = new ArrayList(); >> + ret.add( (Element) evaluated ); >> return ret; >> } >> else >> @@ -303,19 +310,19 @@ >> } >> } >> >> - public List getElementListText( String xpathExpr ) >> + public List getElementListText( String xpathExpr ) >> throws XMLException >> { >> - List elemList = getElementList( xpathExpr ); >> + List elemList = getElementList( xpathExpr ); >> if ( elemList == null ) >> { >> return null; >> } >> >> - List ret = new ArrayList(); >> - for ( Iterator iter = elemList.iterator(); iter.hasNext(); ) >> + List ret = new ArrayList(); >> + for ( Iterator 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/