/*
 * MIT License
 *
 * Copyright (c) 2014-16, Miguel Gamboa (gamboa.pt)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package htmlflow.test;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * @author Miguel Gamboa
 * Created on 22-01-2016.
 */
public class Utils {

    private Utils() {}

    static Element getRootElement(byte[] input) throws SAXException, IOException, ParserConfigurationException {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setValidating(false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document doc = builder.parse(new ByteArrayInputStream(input));
        return doc.getDocumentElement();
    }
}

@@ -1169,16 +1169,44 @@
 .test;%0A%0A
+import htmlflow.HtmlWriter;%0A
 import o
@@ -1434,16 +1434,47 @@
 eption;%0A
+import java.io.BufferedReader;%0A
 import j
@@ -1517,27 +1517,250 @@
 java.io.
-IOException
+ByteArrayOutputStream;%0Aimport java.io.Closeable;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.io.PrintStream;%0Aimport java.io.UncheckedIOException;%0Aimport java.util.stream.Stream
 ;%0A%0A/**%0A 
@@ -2400,10 +2400,1388 @@
 ;%0A    %7D%0A
+%0A    static %3CT%3E Stream%3CString%3E html(HtmlWriter%3CT%3E view, T model)%7B%0A        try(%0A                ByteArrayOutputStream mem = new ByteArrayOutputStream();%0A                PrintStream out = new PrintStream(mem))%0A        %7B%0A            view.setPrintStream(out).write(model);%0A            InputStreamReader actual = new InputStreamReader(new ByteArrayInputStream(mem.toByteArray()));%0A            return new BufferedReader(actual).lines();%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    static Stream%3CString%3E loadLines(String path) %7B%0A        try%7B%0A            InputStream in = TestDivDetails.class%0A                    .getClassLoader()%0A                    .getResource(path)%0A                    .openStream();%0A            BufferedReader reader = new BufferedReader(new InputStreamReader(in));%0A            return reader.lines().onClose(asUncheckedRunnable(reader));%0A        %7D catch (IOException e) %7B%0A            throw new UncheckedIOException(e);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Convert a Closeable to a Runnable by converting checked IOException%0A     * to UncheckedIOException%0A     */%0A    private static Runnable asUncheckedRunnable(Closeable c) %7B%0A        return () -%3E %7B%0A            try %7B%0A                c.close();%0A            %7D catch (IOException e) %7B%0A                throw new UncheckedIOException(e);%0A            %7D%0A        %7D;%0A    %7D%0A%0A
 %7D%0A

Add 2 auxiliary functions to create Stream<lines>: from an HtmlView and from a resource.