use of org.eclipse.rdf4j.query.resultio.BooleanQueryResultParser in project rdf4j by eclipse.
the class SPARQLProtocolSession method getBoolean.
/**
* Parse the response in this thread using a suitable {@link BooleanQueryResultParser}. All HTTP
* connections are closed and released in this method
*
* @throws RDF4JException
*/
protected boolean getBoolean(HttpUriRequest method) throws IOException, RDF4JException {
// Specify which formats we support using Accept headers
Set<QueryResultFormat> booleanFormats = BooleanQueryResultParserRegistry.getInstance().getKeys();
if (booleanFormats.isEmpty()) {
throw new RepositoryException("No boolean query result parsers have been registered");
}
// send the tuple query
HttpResponse response = sendBooleanQueryViaHttp(method, booleanFormats);
try {
// if we get here, HTTP code is 200
String mimeType = getResponseMIMEType(response);
try {
QueryResultFormat format = BooleanQueryResultFormat.matchMIMEType(mimeType, booleanFormats).orElseThrow(() -> new RepositoryException("Server responded with an unsupported file format: " + mimeType));
BooleanQueryResultParser parser = QueryResultIO.createBooleanParser(format);
QueryResultCollector results = new QueryResultCollector();
parser.setQueryResultHandler(results);
parser.parseQueryResult(response.getEntity().getContent());
return results.getBoolean();
} catch (QueryResultParseException e) {
throw new RepositoryException("Malformed query result from server", e);
}
} finally {
EntityUtils.consumeQuietly(response.getEntity());
}
}
Aggregations