private String toString(TupleQueryResult results)
      throws QueryResultHandlerException, TupleQueryResultHandlerException,
          QueryEvaluationException, UnsupportedEncodingException {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(results, writer);

    return out.toString("UTF-8");
  }
Exemplo n.º 2
0
  private TupleQueryResult readExpectedTupleQueryResult() throws Exception {
    TupleQueryResultFormat tqrFormat = QueryResultIO.getParserFormatForFileName(resultFileURL);

    if (tqrFormat != null) {
      InputStream in = new URL(resultFileURL).openStream();
      try {
        TupleQueryResultParser parser = QueryResultIO.createParser(tqrFormat);
        parser.setValueFactory(dataRep.getValueFactory());

        TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder();
        parser.setTupleQueryResultHandler(qrBuilder);

        parser.parse(in);
        return qrBuilder.getQueryResult();
      } finally {
        in.close();
      }
    } else {
      Set<Statement> resultGraph = readExpectedGraphQueryResult();
      return DAWGTestResultSetUtil.toTupleQueryResult(resultGraph);
    }
  }
Exemplo n.º 3
0
  private boolean readExpectedBooleanQueryResult() throws Exception {
    BooleanQueryResultFormat bqrFormat =
        BooleanQueryResultParserRegistry.getInstance().getFileFormatForFileName(resultFileURL);

    if (bqrFormat != null) {
      InputStream in = new URL(resultFileURL).openStream();
      try {
        return QueryResultIO.parse(in, bqrFormat);
      } finally {
        in.close();
      }
    } else {
      Set<Statement> resultGraph = readExpectedGraphQueryResult();
      return DAWGTestResultSetUtil.toBooleanQueryResult(resultGraph);
    }
  }