Package org.eclipse.rdf4j.query.resultio
Class QueryResultIO
- java.lang.Object
-
- org.eclipse.rdf4j.query.resultio.QueryResultIO
-
public class QueryResultIO extends java.lang.ObjectClass offering utility methods related to query results.
-
-
Field Summary
Fields Modifier and Type Field Description private static ConcurrentCleanercleaner
-
Constructor Summary
Constructors Constructor Description QueryResultIO()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static BooleanQueryResultParsercreateBooleanParser(QueryResultFormat format)Convenience methods for creating BooleanQueryResultParser objects.This method uses the registry returned byBooleanQueryResultParserRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate parser.static BooleanQueryResultWritercreateBooleanWriter(QueryResultFormat format, java.io.OutputStream out)Convenience methods for creating BooleanQueryResultWriter objects.This method uses the registry returned byBooleanQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.static TupleQueryResultParsercreateTupleParser(QueryResultFormat format)Convenience methods for creating TupleQueryResultParser objects.static TupleQueryResultParsercreateTupleParser(QueryResultFormat format, ValueFactory valueFactory)Convenience methods for creating TupleQueryResultParser objects that use the specified ValueFactory to create RDF model objects.static TupleQueryResultWritercreateTupleWriter(QueryResultFormat format, java.io.OutputStream out)Convenience methods for creating TupleQueryResultWriter objects.This method uses the registry returned byTupleQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.static QueryResultWritercreateWriter(QueryResultFormat format, java.io.OutputStream out)Convenience methods for creating QueryResultWriter objects.This method uses the registry returned byTupleQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.static java.util.Optional<QueryResultFormat>getBooleanParserFormatForFileName(java.lang.String fileName)Tries to match the extension of a file name against the list of RDF formats that can be parsed.static java.util.Optional<QueryResultFormat>getBooleanParserFormatForMIMEType(java.lang.String mimeType)Tries to match a MIME type against the list of boolean query result formats that can be parsed.static java.util.Optional<QueryResultFormat>getBooleanWriterFormatForFileName(java.lang.String fileName)Tries to match the extension of a file name against the list of RDF formats that can be written.static java.util.Optional<QueryResultFormat>getBooleanWriterFormatForMIMEType(java.lang.String mimeType)Tries to match a MIME type against the list of boolean query result formats that can be written.static java.util.Optional<QueryResultFormat>getParserFormatForFileName(java.lang.String fileName)Tries to match the extension of a file name against the list of RDF formats that can be parsed.static java.util.Optional<QueryResultFormat>getParserFormatForMIMEType(java.lang.String mimeType)Tries to match a MIME type against the list of tuple query result formats that can be parsed.static java.util.Optional<QueryResultFormat>getWriterFormatForFileName(java.lang.String fileName)Tries to match the extension of a file name against the list of RDF formats that can be written.static java.util.Optional<QueryResultFormat>getWriterFormatForMIMEType(java.lang.String mimeType)Tries to match a MIME type against the list of tuple query result formats that can be written.static booleanparseBoolean(java.io.InputStream in, QueryResultFormat format)Parses a boolean query result document and returns the parsed value.static TupleQueryResultparseTuple(java.io.InputStream in, QueryResultFormat format, java.lang.ref.WeakReference<?> callerReference)Deprecated.WeakReference> callerReference argument will be removedstatic voidparseTuple(java.io.InputStream in, QueryResultFormat format, TupleQueryResultHandler handler, ValueFactory valueFactory)Parses a query result document, reporting the parsed solutions to the supplied TupleQueryResultHandler.static TupleQueryResultparseTupleBackground(java.io.InputStream in, QueryResultFormat format, java.lang.ref.WeakReference<?> callerReference)Deprecated.WeakReference> callerReference argument will be removedprivate static TupleQueryResultparseTupleInternal(java.io.InputStream in, QueryResultFormat format, boolean parseOnBackgroundThread)static voidwriteBoolean(boolean value, QueryResultFormat format, java.io.OutputStream out)Writes a boolean query result document in a specific boolean query result format to an output stream.static voidwriteGraph(GraphQueryResult gqr, RDFFormat format, java.io.OutputStream out)Writes a graph query result document in a specific RDF format to an output stream.static voidwriteTuple(TupleQueryResult tqr, QueryResultFormat format, java.io.OutputStream out)Writes a query result document in a specific query result format to an output stream.
-
-
-
Field Detail
-
cleaner
private static final ConcurrentCleaner cleaner
-
-
Method Detail
-
getParserFormatForMIMEType
public static java.util.Optional<QueryResultFormat> getParserFormatForMIMEType(java.lang.String mimeType)
Tries to match a MIME type against the list of tuple query result formats that can be parsed.- Parameters:
mimeType- A MIME type, e.g. "application/sparql-results+xml".- Returns:
- An RDFFormat object if a match was found, or
Optional.empty()otherwise.
-
getParserFormatForFileName
public static java.util.Optional<QueryResultFormat> getParserFormatForFileName(java.lang.String fileName)
Tries to match the extension of a file name against the list of RDF formats that can be parsed.- Parameters:
fileName- A file name.- Returns:
- An TupleQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
getWriterFormatForMIMEType
public static java.util.Optional<QueryResultFormat> getWriterFormatForMIMEType(java.lang.String mimeType)
Tries to match a MIME type against the list of tuple query result formats that can be written.- Parameters:
mimeType- A MIME type, e.g. "application/sparql-results+xml".- Returns:
- An TupleQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
getWriterFormatForFileName
public static java.util.Optional<QueryResultFormat> getWriterFormatForFileName(java.lang.String fileName)
Tries to match the extension of a file name against the list of RDF formats that can be written.- Parameters:
fileName- A file name.- Returns:
- An TupleQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
getBooleanParserFormatForMIMEType
public static java.util.Optional<QueryResultFormat> getBooleanParserFormatForMIMEType(java.lang.String mimeType)
Tries to match a MIME type against the list of boolean query result formats that can be parsed.- Parameters:
mimeType- A MIME type, e.g. "application/sparql-results+xml".- Returns:
- An RDFFormat object if a match was found, or
Optional.empty()otherwise.
-
getBooleanParserFormatForFileName
public static java.util.Optional<QueryResultFormat> getBooleanParserFormatForFileName(java.lang.String fileName)
Tries to match the extension of a file name against the list of RDF formats that can be parsed.- Parameters:
fileName- A file name.- Returns:
- An BooleanQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
getBooleanWriterFormatForMIMEType
public static java.util.Optional<QueryResultFormat> getBooleanWriterFormatForMIMEType(java.lang.String mimeType)
Tries to match a MIME type against the list of boolean query result formats that can be written.- Parameters:
mimeType- A MIME type, e.g. "application/sparql-results+xml".- Returns:
- An BooleanQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
getBooleanWriterFormatForFileName
public static java.util.Optional<QueryResultFormat> getBooleanWriterFormatForFileName(java.lang.String fileName)
Tries to match the extension of a file name against the list of RDF formats that can be written.- Parameters:
fileName- A file name.- Returns:
- An BooleanQueryResultFormat object if a match was found, or
Optional.empty()otherwise.
-
createTupleParser
public static TupleQueryResultParser createTupleParser(QueryResultFormat format) throws UnsupportedQueryResultFormatException
Convenience methods for creating TupleQueryResultParser objects. This method uses the registry returned byTupleQueryResultParserRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate parser.- Returns:
- A TupleQueryResultParser matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no parser is available for the specified tuple query result format.
-
createTupleParser
public static TupleQueryResultParser createTupleParser(QueryResultFormat format, ValueFactory valueFactory) throws UnsupportedQueryResultFormatException
Convenience methods for creating TupleQueryResultParser objects that use the specified ValueFactory to create RDF model objects.- Parameters:
format-valueFactory-- Returns:
- A TupleQueryResultParser matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no parser is available for the specified tuple query result format.- See Also:
QueryResultParser.setValueFactory(ValueFactory)
-
createTupleWriter
public static TupleQueryResultWriter createTupleWriter(QueryResultFormat format, java.io.OutputStream out) throws UnsupportedQueryResultFormatException
Convenience methods for creating TupleQueryResultWriter objects.This method uses the registry returned byTupleQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.- Parameters:
format-out-- Returns:
- A TupleQueryResultWriter matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no writer is available for the specified tuple query result format.
-
createBooleanParser
public static BooleanQueryResultParser createBooleanParser(QueryResultFormat format) throws UnsupportedQueryResultFormatException
Convenience methods for creating BooleanQueryResultParser objects.This method uses the registry returned byBooleanQueryResultParserRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate parser.- Parameters:
format-- Returns:
- A BooleanQueryResultParser matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no parser is available for the specified boolean query result format.
-
createBooleanWriter
public static BooleanQueryResultWriter createBooleanWriter(QueryResultFormat format, java.io.OutputStream out) throws UnsupportedQueryResultFormatException
Convenience methods for creating BooleanQueryResultWriter objects.This method uses the registry returned byBooleanQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.- Parameters:
format-out-- Returns:
- A BooleanQueryResultWriter matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no writer is available for the specified boolean query result format.
-
createWriter
public static QueryResultWriter createWriter(QueryResultFormat format, java.io.OutputStream out) throws UnsupportedQueryResultFormatException
Convenience methods for creating QueryResultWriter objects.This method uses the registry returned byTupleQueryResultWriterRegistry.getInstance()to get a factory for the specified format and uses this factory to create the appropriate writer.- Parameters:
format-out-- Returns:
- A QueryResultWriter matching the given format.
- Throws:
UnsupportedQueryResultFormatException- If no writer is available for the specified tuple query result format.
-
parseTuple
public static void parseTuple(java.io.InputStream in, QueryResultFormat format, TupleQueryResultHandler handler, ValueFactory valueFactory) throws java.io.IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatExceptionParses a query result document, reporting the parsed solutions to the supplied TupleQueryResultHandler.- Parameters:
in- An InputStream to read the query result document from.format- The query result format of the document to parse. SeeTupleQueryResultFormatfor the list of supported formats.handler- The TupleQueryResultHandler to report the parse results to.valueFactory-- Throws:
java.io.IOException- If an I/O error occurred while reading the query result document from the stream.TupleQueryResultHandlerException- If such an exception is thrown by the supplied TupleQueryResultHandler.UnsupportedQueryResultFormatExceptionjava.lang.IllegalArgumentException- If an unsupported query result file format was specified.QueryResultParseException
-
parseTuple
@Deprecated(since="4.1.2") public static TupleQueryResult parseTuple(java.io.InputStream in, QueryResultFormat format, java.lang.ref.WeakReference<?> callerReference) throws java.io.IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException
Deprecated.WeakReference> callerReference argument will be removedParses a query result document and returns it as a TupleQueryResult object.- Parameters:
in- An InputStream to read the query result document from.format- The query result format of the document to parse. SeeTupleQueryResultFormatfor the list of supported formats.- Returns:
- A TupleQueryResult containing the query results.
- Throws:
java.io.IOException- If an I/O error occurred while reading the query result document from the stream.TupleQueryResultHandlerException- If such an exception is thrown by the used query result parser.UnsupportedQueryResultFormatExceptionjava.lang.IllegalArgumentException- If an unsupported query result file format was specified.QueryResultParseException
-
parseTupleBackground
@Deprecated(since="4.1.2") public static TupleQueryResult parseTupleBackground(java.io.InputStream in, QueryResultFormat format, java.lang.ref.WeakReference<?> callerReference) throws java.io.IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException
Deprecated.WeakReference> callerReference argument will be removedParses a query result document and returns it as a TupleQueryResult object, with parsing done on a separate thread in the background.
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.- Parameters:
in- An InputStream to read the query result document from.format- The query result format of the document to parse. SeeTupleQueryResultFormatfor the list of supported formats.- Returns:
- A TupleQueryResult containing the query results, which must be closed to prevent resource leaks.
- Throws:
java.io.IOException- If an I/O error occurred while reading the query result document from the stream.TupleQueryResultHandlerException- If such an exception is thrown by the used query result parser.UnsupportedQueryResultFormatExceptionjava.lang.IllegalArgumentException- If an unsupported query result file format was specified.QueryResultParseException
-
parseTupleInternal
private static TupleQueryResult parseTupleInternal(java.io.InputStream in, QueryResultFormat format, boolean parseOnBackgroundThread) throws java.io.IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException
- Throws:
java.io.IOExceptionQueryResultParseExceptionTupleQueryResultHandlerExceptionUnsupportedQueryResultFormatException
-
parseBoolean
public static boolean parseBoolean(java.io.InputStream in, QueryResultFormat format) throws java.io.IOException, QueryResultParseException, UnsupportedQueryResultFormatExceptionParses a boolean query result document and returns the parsed value.- Parameters:
in- An InputStream to read the query result document from.format- The file format of the document to parse.- Returns:
- A boolean representing the result of parsing the given InputStream.
- Throws:
java.io.IOException- If an I/O error occurred while reading the query result document from the stream.UnsupportedQueryResultFormatException- If an unsupported query result file format was specified.QueryResultParseException
-
writeTuple
public static void writeTuple(TupleQueryResult tqr, QueryResultFormat format, java.io.OutputStream out) throws java.io.IOException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException, QueryEvaluationException
Writes a query result document in a specific query result format to an output stream.- Parameters:
tqr- The query result to write.format- The file format of the document to write.out- An OutputStream to write the document to.- Throws:
java.io.IOException- If an I/O error occurred while writing the query result document to the stream.TupleQueryResultHandlerException- If such an exception is thrown by the used query result writer.UnsupportedQueryResultFormatExceptionQueryEvaluationException- If an unsupported query result file format was specified.
-
writeBoolean
public static void writeBoolean(boolean value, QueryResultFormat format, java.io.OutputStream out) throws QueryResultHandlerException, UnsupportedQueryResultFormatExceptionWrites a boolean query result document in a specific boolean query result format to an output stream.- Parameters:
value- The value to write.format- The file format of the document to write.out- An OutputStream to write the document to.- Throws:
QueryResultHandlerException- If an I/O or other error occurred while writing the query result document to the stream.UnsupportedQueryResultFormatException- If an unsupported query result file format was specified.
-
writeGraph
public static void writeGraph(GraphQueryResult gqr, RDFFormat format, java.io.OutputStream out) throws java.io.IOException, RDFHandlerException, UnsupportedRDFormatException, QueryEvaluationException
Writes a graph query result document in a specific RDF format to an output stream.- Parameters:
gqr- The query result to write.format- The file format of the document to write.out- An OutputStream to write the document to.- Throws:
java.io.IOException- If an I/O error occurred while writing the query result document to the stream.RDFHandlerException- If such an exception is thrown by the used RDF writer.QueryEvaluationExceptionUnsupportedRDFormatException- If an unsupported query result file format was specified.
-
-