From: <bo...@us...> - 2014-12-04 17:36:25
|
Revision: 565 http://sourceforge.net/p/xmlunit/code/565 Author: bodewig Date: 2014-12-04 17:36:17 +0000 (Thu, 04 Dec 2014) Log Message: ----------- input builder for NIO channels Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.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 2014-12-01 21:00:51 UTC (rev 564) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2014-12-04 17:36:17 UTC (rev 565) @@ -23,6 +23,8 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; import javax.xml.transform.Source; import javax.xml.transform.TransformerFactory; import javax.xml.transform.URIResolver; @@ -134,6 +136,13 @@ } /** + * Build a Source from a channel. + */ + public static Builder fromChannel(ReadableByteChannel c) { + return fromStream(Channels.newInputStream(c)); + } + + /** * Build a Source from an URL. */ public static Builder fromURL(URL url) { Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2014-12-01 21:00:51 UTC (rev 564) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2014-12-04 17:36:17 UTC (rev 565) @@ -19,6 +19,7 @@ import java.io.FileReader; import java.net.URI; import java.net.URL; +import java.nio.channels.FileChannel; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; @@ -83,6 +84,23 @@ } } + @Test public void shouldParseAnExistingFileFromChannel() throws Exception { + FileChannel fc = null; + FileInputStream is = null; + try { + is = new FileInputStream(TestResources.ANIMAL_FILE); + fc = is.getChannel(); + allIsWellFor(Input.fromChannel(fc).build()); + } finally { + if (fc != null) { + fc.close(); + } + if (is != null) { + is.close(); + } + } + } + @Test public void shouldParseString() throws Exception { allIsWellFor(Input.fromMemory(new String(readTestFile(), "UTF-8")) .build()); @@ -173,4 +191,4 @@ return false; } } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |