From: <bo...@us...> - 2009-05-12 04:29:36
|
Revision: 316 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=316&view=rev Author: bodewig Date: 2009-05-12 04:29:34 +0000 (Tue, 12 May 2009) Log Message: ----------- wrap checked exception's Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ConfigurationException.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitRuntimeException.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2009-05-11 10:13:41 UTC (rev 315) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2009-05-12 04:29:34 UTC (rev 316) @@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStream; +import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.net.URI; @@ -30,6 +31,8 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; +import net.sf.xmlunit.exceptions.ConfigurationException; +import net.sf.xmlunit.exceptions.XMLUnitRuntimeException; import org.w3c.dom.Document; public class Input { @@ -94,32 +97,46 @@ return fromStream(new ByteArrayInputStream(b)); } - public static Builder fromURL(URL url) throws Exception { - InputStream in = null; + public static Builder fromURL(URL url) { try { - in = url.openStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int read = -1; - byte[] buf = new byte[4096]; - while ((read = in.read(buf)) >= 0) { - if (read > 0) { - baos.write(buf, 0, read); + InputStream in = null; + try { + in = url.openStream(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int read = -1; + byte[] buf = new byte[4096]; + while ((read = in.read(buf)) >= 0) { + if (read > 0) { + baos.write(buf, 0, read); + } } + return fromMemory(baos.toByteArray()); + } finally { + if (in != null) { + in.close(); + } } - return fromMemory(baos.toByteArray()); - } finally { - if (in != null) { - in.close(); - } + } catch (IOException ex) { + throw new XMLUnitRuntimeException(ex); } } - public static Builder fromURI(URI uri) throws Exception { - return fromURL(uri.toURL()); + public static Builder fromURI(URI uri) { + try { + return fromURL(uri.toURL()); + } catch (java.net.MalformedURLException ex) { + throw new IllegalArgumentException("uri " + uri + " is not an URL", + ex); + } } - public static Builder fromURI(String uri) throws Exception { + public static Builder fromURI(String uri) { + try { return fromURI(new URI(uri)); + } catch (java.net.URISyntaxException ex) { + throw new IllegalArgumentException("uri " + uri + " is not an URI", + ex); + } } public static interface TransformationBuilder extends Builder { @@ -168,8 +185,10 @@ } t.transform(source, r); return new DOMSource(r.getNode()); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (javax.xml.transform.TransformerConfigurationException e) { + throw new ConfigurationException(e); + } catch (javax.xml.transform.TransformerException e) { + throw new XMLUnitRuntimeException(e); } } } Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ConfigurationException.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ConfigurationException.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ConfigurationException.java 2009-05-12 04:29:34 UTC (rev 316) @@ -0,0 +1,24 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package net.sf.xmlunit.exceptions; + +/** + * Exception thrown when anything inside JAXP throws a + * *ConfigurationException. + */ +public class ConfigurationException extends XMLUnitRuntimeException { + public ConfigurationException(Throwable cause) { + super(cause); + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/ConfigurationException.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitRuntimeException.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitRuntimeException.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitRuntimeException.java 2009-05-12 04:29:34 UTC (rev 316) @@ -0,0 +1,47 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package net.sf.xmlunit.exceptions; + +/** + * Base class of any Exception thrown within XMLUnit. + */ +public class XMLUnitRuntimeException extends RuntimeException { + /** + * Inititializes the exeption. + * + * @param message the detail message + * @param cause the root cause of the exception + */ + public XMLUnitRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Inititializes an exeption without cause. + * + * @param message the detail message + */ + public XMLUnitRuntimeException(String message) { + this(message, null); + } + + /** + * Inititializes an exeption using the wrapped exception's message. + * + * @param message the detail message + */ + public XMLUnitRuntimeException(Throwable cause) { + this(cause != null ? cause.getMessage() : null, cause); + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/exceptions/XMLUnitRuntimeException.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |