use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class QueryResultIO method parseBoolean.
/**
* Parses a boolean query result document and returns the parsed value.
*
* @param in
* An InputStream to read the query result document from.
* @param format
* The file format of the document to parse.
* @return A boolean representing the result of parsing the given InputStream.
* @throws IOException
* If an I/O error occured while reading the query result document from the stream.
* @throws UnsupportedQueryResultFormatException
* If an unsupported query result file format was specified.
*/
public static boolean parseBoolean(InputStream in, QueryResultFormat format) throws IOException, QueryResultParseException, UnsupportedQueryResultFormatException {
BooleanQueryResultParser parser = createBooleanParser(format);
try {
QueryResultCollector handler = new QueryResultCollector();
parser.setQueryResultHandler(handler);
parser.parseQueryResult(in);
if (handler.getHandledBoolean()) {
return handler.getBoolean();
} else {
throw new QueryResultParseException("Did not find a boolean result");
}
} catch (QueryResultHandlerException e) {
throw new QueryResultParseException(e);
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method startHeader.
@Override
public void startHeader() throws QueryResultHandlerException {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
try {
// Write header
jg.writeObjectFieldStart("head");
headerOpen = true;
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method endQueryResult.
@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
if (!headerComplete) {
endHeader();
}
if (!tupleVariablesFound) {
throw new IllegalStateException("Could not end query result as startQueryResult was not called first.");
}
// bindings array
jg.writeEndArray();
// results braces
jg.writeEndObject();
endDocument();
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
} catch (TupleQueryResultHandlerException e) {
throw e;
} catch (QueryResultHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method handleLinks.
@Override
public void handleLinks(List<String> linkUrls) throws QueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
jg.writeArrayFieldStart("link");
for (String nextLink : linkUrls) {
jg.writeString(nextLink);
}
jg.writeEndArray();
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLXMLWriter method handleLinks.
@Override
public void handleLinks(List<String> linkUrls) throws QueryResultHandlerException {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
try {
// Write link URLs
for (String name : linkUrls) {
xmlWriter.setAttribute(HREF_ATT, name);
xmlWriter.emptyElement(LINK_TAG);
}
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
Aggregations