diff options
author | Olivier Lamy <olamy@apache.org> | 2014-04-16 18:11:38 +1000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-04-16 18:11:38 +1000 |
commit | ec1e655c9d996f20bd231b21505a6df865d8a1f7 (patch) | |
tree | 83a6e56ba6b0e2a0f9e0bd97c2ddd1b05b5d90aa /archiva-modules/archiva-base/archiva-xml-tools | |
parent | 767e00c182085b193c9f2481a815e90c5c054095 (diff) | |
download | archiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.tar.gz archiva-ec1e655c9d996f20bd231b21505a6df865d8a1f7.zip |
use Files.copy from java.nio.file
Diffstat (limited to 'archiva-modules/archiva-base/archiva-xml-tools')
-rw-r--r-- | archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java b/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java index 43cb09c4b..603fc884e 100644 --- a/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java +++ b/archiva-modules/archiva-base/archiva-xml-tools/src/main/java/org/apache/archiva/xml/XMLReader.java @@ -19,7 +19,6 @@ package org.apache.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; @@ -44,9 +43,7 @@ import java.util.List; import java.util.Map; /** - * XMLReader - a set of common xml utility methods for reading content out of an xml file. - * - * + * XMLReader - a set of common xml utility methods for reading content out of an xml file. */ public class XMLReader { @@ -98,12 +95,10 @@ public class XMLReader this.documentType = type; this.xmlUrl = url; - InputStream in = null; SAXReader reader = new SAXReader(); - - try + + 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 ); @@ -116,10 +111,6 @@ 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 ) @@ -129,8 +120,9 @@ public class XMLReader if ( !StringUtils.equals( root.getName(), documentType ) ) { - throw new XMLException( "Invalid " + documentType + " xml: Unexpected root element <" + root.getName() - + ">, expected <" + documentType + ">" ); + throw new XMLException( + "Invalid " + documentType + " xml: Unexpected root element <" + root.getName() + ">, expected <" + + documentType + ">" ); } } @@ -164,7 +156,7 @@ public class XMLReader { // Unknown evaluated type. throw new XMLException( ".getElement( Expr: " + xpathExpr + " ) resulted in non-Element type -> (" - + evaluated.getClass().getName() + ") " + evaluated ); + + evaluated.getClass().getName() + ") " + evaluated ); } } @@ -246,8 +238,8 @@ public class XMLReader else { // Unknown evaluated type. - throw new XMLException( ".getElementText( Node, Expr: " + xpathExpr - + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated ); + throw new XMLException( ".getElementText( Node, Expr: " + xpathExpr + " ) resulted in non-Element type -> (" + + evaluated.getClass().getName() + ") " + evaluated ); } } @@ -271,7 +263,7 @@ public class XMLReader { // Unknown evaluated type. throw new XMLException( ".getElementText( Expr: " + xpathExpr + " ) resulted in non-Element type -> (" - + evaluated.getClass().getName() + ") " + evaluated ); + + evaluated.getClass().getName() + ") " + evaluated ); } } @@ -306,7 +298,7 @@ public class XMLReader { // Unknown evaluated type. throw new XMLException( ".getElementList( Expr: " + xpathExpr + " ) resulted in non-List type -> (" - + evaluated.getClass().getName() + ") " + evaluated ); + + evaluated.getClass().getName() + ") " + evaluated ); } } |