/** * Convenience methods for creating TupleQueryResultParser objects that use the specified ValueFactory to * create RDF model objects. * * @return A TupleQueryResultParser matching the given format. * @throws UnsupportedQueryResultFormatException * If no parser is available for the specified tuple query result format. * @see #createParser(TupleQueryResultFormat) * @see TupleQueryResultParser#setValueFactory(ValueFactory) */ public static TupleQueryResultParser createTupleParser(QueryResultFormat format, ValueFactory valueFactory) throws UnsupportedQueryResultFormatException { TupleQueryResultParser parser = createTupleParser(format); parser.setValueFactory(valueFactory); return parser; }
private Boolean parseBooleanResult(Response theResponse) throws QueryResultParseException, UnsupportedQueryResultFormatException, IOException { return QueryResultIO.parseBoolean(theResponse.getContent(), BooleanQueryResultFormat.SPARQL); }
/** * Parses a query result document and returns it as a TupleQueryResult object. * * @param in * An InputStream to read the query result document from. * @param format * The query result format of the document to parse. Supported formats are * {@link TupleQueryResultFormat#SPARQL} and {@link TupleQueryResultFormat#BINARY}. * @return A TupleQueryResult containing the query results. * @throws IOException * If an I/O error occured while reading the query result document from the stream. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result parser. * @throws UnsupportedQueryResultFormatException * @throws IllegalArgumentException * If an unsupported query result file format was specified. */ public static TupleQueryResult parseTuple(InputStream in, QueryResultFormat format) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException { return parseTupleInternal(in, format, false); }
@Override public void handleResponse(HttpMethod method) throws IOException, AGHttpException { String mimeType = getResponseMIMEType(method); if (!mimeType.equals(getRequestMIMEType())) { throw new AGHttpException("unexpected response MIME type: " + mimeType); } InputStream response = getInputStream(method); try { BooleanQueryResultFormat format = BooleanQueryResultFormat.TEXT; BooleanQueryResultParser parser = QueryResultIO.createBooleanParser(format); result = parser.parse(response); } catch (QueryResultParseException e) { throw new AGHttpException(e); } }
private TupleQueryResult readExpectedTupleQueryResult() throws Exception { Optional<QueryResultFormat> tqrFormat = QueryResultIO.getParserFormatForFileName(resultFileURL); if (tqrFormat.isPresent()) { InputStream in = new URL(resultFileURL).openStream(); try { TupleQueryResultParser parser = QueryResultIO.createTupleParser(tqrFormat.get()); parser.setValueFactory(dataRep.getValueFactory()); TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder(); parser.setQueryResultHandler(qrBuilder); parser.parseQueryResult(in); return qrBuilder.getQueryResult(); } finally { in.close(); } } else { Set<Statement> resultGraph = readExpectedGraphQueryResult(); return DAWGTestResultSetUtil.toTupleQueryResult(resultGraph); } }
/** * Writes a boolean query result document in a specific boolean query result format to an output stream. * * @param value * The value to write. * @param format * The file format of the document to write. * @param out * An OutputStream to write the document to. * @throws IOException * If an I/O error occured while writing the query result document to the stream. * @throws UnsupportedQueryResultFormatException * If an unsupported query result file format was specified. */ public static void writeBoolean(boolean value, QueryResultFormat format, OutputStream out) throws QueryResultHandlerException, UnsupportedQueryResultFormatException { BooleanQueryResultWriter writer = createBooleanWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleBoolean(value); }
QueryEvaluationException TupleQueryResultWriter writer = createTupleWriter(format, out); try { writer.startDocument();
() -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); BooleanQueryResultParser parser = QueryResultIO.createBooleanParser(format); QueryResultCollector results = new QueryResultCollector(); parser.setQueryResultHandler(results);
/** * Writes a boolean query result document in a specific boolean query result format to an output stream. * * @param value * The value to write. * @param format * The file format of the document to write. * @param out * An OutputStream to write the document to. * @throws IOException * If an I/O error occured while writing the query result document to the stream. * @throws UnsupportedQueryResultFormatException * If an unsupported query result file format was specified. */ public static void writeBoolean(boolean value, QueryResultFormat format, OutputStream out) throws QueryResultHandlerException, UnsupportedQueryResultFormatException { BooleanQueryResultWriter writer = createBooleanWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleBoolean(value); }
QueryEvaluationException TupleQueryResultWriter writer = createTupleWriter(format, out); try { writer.startDocument();
/** * Convenience methods for creating TupleQueryResultParser objects that use the specified ValueFactory to * create RDF model objects. * * @return A TupleQueryResultParser matching the given format. * @throws UnsupportedQueryResultFormatException * If no parser is available for the specified tuple query result format. * @see #createParser(TupleQueryResultFormat) * @see TupleQueryResultParser#setValueFactory(ValueFactory) */ public static TupleQueryResultParser createTupleParser(QueryResultFormat format, ValueFactory valueFactory) throws UnsupportedQueryResultFormatException { TupleQueryResultParser parser = createTupleParser(format); parser.setValueFactory(valueFactory); return parser; }
() -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); BooleanQueryResultParser parser = QueryResultIO.createBooleanParser(format); QueryResultCollector results = new QueryResultCollector(); parser.setQueryResultHandler(results);
/** * Parses a query result document and returns it as a TupleQueryResult object. * * @param in * An InputStream to read the query result document from. * @param format * The query result format of the document to parse. Supported formats are * {@link TupleQueryResultFormat#SPARQL} and {@link TupleQueryResultFormat#BINARY}. * @return A TupleQueryResult containing the query results. * @throws IOException * If an I/O error occured while reading the query result document from the stream. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result parser. * @throws UnsupportedQueryResultFormatException * @throws IllegalArgumentException * If an unsupported query result file format was specified. */ public static TupleQueryResult parseTuple(InputStream in, QueryResultFormat format) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException { return parseTupleInternal(in, format, false); }
private boolean readExpectedBooleanQueryResult() throws Exception { Optional<QueryResultFormat> bqrFormat = BooleanQueryResultParserRegistry.getInstance().getFileFormatForFileName(resultFileURL); if (bqrFormat.isPresent()) { InputStream in = new URL(resultFileURL).openStream(); try { return QueryResultIO.parseBoolean(in, bqrFormat.get()); } finally { in.close(); } } else { Set<Statement> resultGraph = readExpectedGraphQueryResult(); return DAWGTestResultSetUtil.toBooleanQueryResult(resultGraph); } }
() -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); TupleQueryResultParser parser = QueryResultIO.createTupleParser(format, getValueFactory()); tRes = background.parse(parser, response.getEntity().getContent()); submitted = true;
() -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); BooleanQueryResultParser parser = QueryResultIO.createBooleanParser(format); QueryResultCollector results = new QueryResultCollector(); parser.setQueryResultHandler(results);
/** * Parses a query result document and returns it as a TupleQueryResult object, with parsing done on a * separate thread in the background.<br> * IMPORTANT: As this method may spawn a new thread in the background, it is vitally important that the * TupleQueryResult be closed consistently when it is no longer required, to prevent resource leaks. * * @param in * An InputStream to read the query result document from. * @param format * The query result format of the document to parse. Supported formats are * {@link TupleQueryResultFormat#SPARQL} and {@link TupleQueryResultFormat#BINARY}. * @return A TupleQueryResult containing the query results, which must be closed to prevent resource * leaks. * @throws IOException * If an I/O error occured while reading the query result document from the stream. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result parser. * @throws UnsupportedQueryResultFormatException * @throws IllegalArgumentException * If an unsupported query result file format was specified. */ public static TupleQueryResult parseTupleBackground(InputStream in, QueryResultFormat format) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException { return parseTupleInternal(in, format, true); }
() -> new RepositoryException( "Server responded with an unsupported file format: " + mimeType)); TupleQueryResultParser parser = QueryResultIO.createTupleParser(format, getValueFactory()); tRes = background.parse(parser, response.getEntity().getContent()); submitted = true;
throws IOException, QueryResultParseException, UnsupportedQueryResultFormatException BooleanQueryResultParser parser = createBooleanParser(format); try {
/** * Parses a query result document and returns it as a TupleQueryResult object, with parsing done on a * separate thread in the background.<br> * IMPORTANT: As this method may spawn a new thread in the background, it is vitally important that the * TupleQueryResult be closed consistently when it is no longer required, to prevent resource leaks. * * @param in * An InputStream to read the query result document from. * @param format * The query result format of the document to parse. Supported formats are * {@link TupleQueryResultFormat#SPARQL} and {@link TupleQueryResultFormat#BINARY}. * @return A TupleQueryResult containing the query results, which must be closed to prevent resource * leaks. * @throws IOException * If an I/O error occured while reading the query result document from the stream. * @throws TupleQueryResultHandlerException * If such an exception is thrown by the used query result parser. * @throws UnsupportedQueryResultFormatException * @throws IllegalArgumentException * If an unsupported query result file format was specified. */ public static TupleQueryResult parseTupleBackground(InputStream in, QueryResultFormat format) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException { return parseTupleInternal(in, format, true); }