docs: private static Result createResults(Command cmd, InputStream stream, ResultType type) throws SparqlException {
      XMLInputFactory xmlStreamFactory = XMLInputFactory.newInstance();
      
      // Tell the factory to combine adjacent character blocks into a single event, so we don't have to do it ourselves.
      xmlStreamFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
      
      // Tell the factory to create a reader that will close the underlying stream when done.
      xmlStreamFactory.setProperty(XMLInputFactory2.P_AUTO_CLOSE_INPUT, true);
      
      XMLStreamReader rdr;
      try {
        rdr = xmlStreamFactory.createXMLStreamReader(stream, "UTF-8");
      } catch (XMLStreamException e) {
        throw new SparqlException("Unable to open XML data", e);
      }
      List<String> cols = new ArrayList<String>();
      List<String> md = new ArrayList<String>();
  
      try {
        if (rdr.nextTag() != START_ELEMENT || !nameIs(rdr, SPARQL)) {
          throw new SparqlException("Result is not a SPARQL XML result document");
        }
        
        // Initialize the base URI to the 
        String base = null;
        if (cmd != null) {
          base = ((ProtocolDataSource)cmd.getConnection().getDataSource()).getUrl().toString();
        }
        
        // read the header information
        parseHeader(base, rdr, cols, md);
        
        // move the cursor into the results, and read in the first row
        if (rdr.nextTag() != START_ELEMENT) throw new SparqlException("No body to result document");
        
        String typeName = rdr.getLocalName();
        if (typeName.equalsIgnoreCase(RESULTS.toString())) {
          if (type != null && type != ResultType.SELECT) {
            throw new SparqlException("Unexpected result type; expected " + type + " but found SELECT.");
          }
          return new XMLSelectResults(cmd, rdr, cols, md);
        }
        if (typeName.equalsIgnoreCase(BOOLEAN.toString())) {
          if (type != null && type != ResultType.ASK) {
            throw new SparqlException("Unexpected result type; expected " + type + " but found ASK.");
          }
          if (!cols.isEmpty()) {
            logger.warn("Boolean result contained column definitions in head: {}", cols);
          }
          return parseBooleanResult(cmd, rdr, md);
        }
  
        throw new SparqlException("Unknown element type in result document. Expected <results> or <boolean> but got <" + typeName + ">");
      } catch (XMLStreamException e) {
        throw new SparqlException("Error reading the XML stream", e);
      }
    }