private SparqlWriter createAnswerWriter(Writer writer) throws XMLStreamException {
final String[] variableNames = answer.getVariableNames();
final Iterator<TypeValue[]> typeValues = answer.columnValuesIterator();
final long maxRows = answer.numberOfTuples();
if (APPLICATION_SPARQL_XML.equals(getMediaType())) {
return new SparqlSelectXmlWriter(writer, variableNames, typeValues, maxRows);
} else if (APPLICATION_SPARQL_JSON.equals(getMediaType())) {
return new SparqlSelectJsonWriter(writer, new String[0], variableNames, typeValues, maxRows);
} else {
throw new RuntimeException("Unknown media type: " + getMediaType());
}