@Override
    public void beginResponse(OutputStream stream) throws IOException {
        Charset cs = Charset.forName(getRequestedEncoding(getResult().getQuery()));
        CharsetEncoder encoder = cs.newEncoder();
        writer = wrapWriter(new ByteWriter(stream, encoder));

        header(writer, getResult());
        if (getResult().hits().getError() != null || getResult().hits().getQuery().errors().size() > 0) {
            error(writer, getResult());
        }

        if (getResult().getConcreteHitCount() == 0) {
            emptyResult(writer, getResult());
        }

        if (getResult().getContext(false) != null) {
            queryContext(writer, getResult().getContext(false), getResult().getQuery());
        }

    }
Creates an XML renderer using a custom executor.
Using a custom executor is useful for tests to avoid creating new threads for each renderer registry.
container-search/src/main/java/com/yahoo/search/rendering/XmlRenderer.java