Search in sources :

Example 1 with QueryResultHandlerException

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);
    }
}
Also used : QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)

Example 2 with QueryResultHandlerException

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);
        }
    }
}
Also used : IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 3 with QueryResultHandlerException

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);
    }
}
Also used : TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 4 with QueryResultHandlerException

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);
    }
}
Also used : IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 5 with QueryResultHandlerException

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);
    }
}
Also used : IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Aggregations

QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)20 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)18 IOException (java.io.IOException)16 QueryResultParseException (org.eclipse.rdf4j.query.resultio.QueryResultParseException)3 Binding (org.eclipse.rdf4j.query.Binding)2 DefaultIndenter (com.fasterxml.jackson.core.util.DefaultIndenter)1 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)1 Indenter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 HttpResponse (org.apache.http.HttpResponse)1 UncloseableInputStream (org.eclipse.rdf4j.common.io.UncloseableInputStream)1 SimpleSAXParser (org.eclipse.rdf4j.common.xml.SimpleSAXParser)1 TupleQueryResultBuilder (org.eclipse.rdf4j.query.impl.TupleQueryResultBuilder)1 BooleanQueryResultFormat (org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat)1 QueryResultFormat (org.eclipse.rdf4j.query.resultio.QueryResultFormat)1 TupleQueryResultFormat (org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat)1 TupleQueryResultParser (org.eclipse.rdf4j.query.resultio.TupleQueryResultParser)1