docs: public static Result getResult(Command cmd, HttpResponse response, ResultType expectedType) throws SparqlException {
      HttpEntity entity = response.getEntity();
      if (entity == null) throw new SparqlException("No data in response from server");
      
      Header header = entity.getContentType();
      String mediaType = (header != null) ? header.getValue() : null;
      
      ResultParser parser = null; 
      try {
        parser = findParser(mediaType, expectedType);
      } catch (SparqlException e) {
        logger.debug("Couldn't find parser to use for protocol response; cleaning up.");
        try {
          entity.getContent().close();
        } catch (IOException ioe) {
          logger.warn("Error cleaning up response for failed protocol command", e);
        }
        throw e;
      }
      assert parser != null:"Could not find result parser";
      
      Result result = null;
      try {
        result = parser.parse(cmd, entity.getContent(), expectedType);
      } catch (IOException e) {
        throw new SparqlException("Error reading response from server", e);
      }
      
      if (result == null) {
        // Don't know how we got here, but parser should have returned a result or thrown an exception.
        throw new IllegalStateException("Could not parse result from server response.");
      }
      
      // Should never happen because the result format should have been validated against the expected
      // class when selecting the format to use for parsing, but check anyways.
      if (expectedType != null && !expectedType.getResultClass().isInstance(result)) {
        try {
          result.close();
        } catch (IOException e) {
          logger.warn("Error closing result of incorrect type", e);
        }
        throw new IllegalStateException("Result parsed from server response (" +
            result.getClass().getName() + ") does not match expected result type (" + expectedType + ")");
      }
      
      return result;
    }