Class BinaryQueryResultWriter
- java.lang.Object
-
- org.eclipse.rdf4j.query.resultio.AbstractQueryResultWriter
-
- org.eclipse.rdf4j.query.resultio.binary.BinaryQueryResultWriter
-
- All Implemented Interfaces:
ByteSink
,Sink
,QueryResultHandler
,QueryResultWriter
,TupleQueryResultWriter
,TupleQueryResultHandler
public class BinaryQueryResultWriter extends AbstractQueryResultWriter implements TupleQueryResultWriter, ByteSink
Writer for the binary tuple result format. The format is explained inBinaryQueryResultConstants
.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
bindingNames
private java.nio.charset.CharsetEncoder
charsetEncoder
private boolean
documentStarted
private java.util.Map<java.lang.String,java.lang.Integer>
namespaceTable
Map containing the namespace IDs (Integer objects) that have been defined in the document, stored using the concerning namespace (Strings).private int
nextNamespaceID
private java.io.DataOutputStream
out
The output stream to write the results table to.private BindingSet
previousBindings
protected boolean
tupleVariablesFound
-
Constructor Summary
Constructors Constructor Description BinaryQueryResultWriter(java.io.OutputStream out)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
endDocument()
void
endHeader()
Indicates the end of the header.void
endQueryResult()
Indicates the end of a sequence of solutions.void
error(QueryErrorType errType, java.lang.String msg)
Writes an error msg to the stream.java.io.OutputStream
getOutputStream()
get theOutputStream
used by thisByteSink
.TupleQueryResultFormat
getQueryResultFormat()
Gets the query result format that this writer uses.java.util.Collection<RioSetting<?>>
getSupportedSettings()
TupleQueryResultFormat
getTupleQueryResultFormat()
Gets the query result format that this writer uses.void
handleBoolean(boolean value)
Handles the specified boolean value.void
handleLinks(java.util.List<java.lang.String> linkUrls)
Handles the links elements which are present in SPARQL Results JSON and SPARQL Results XML documents in the header.void
handleNamespace(java.lang.String prefix, java.lang.String uri)
Handles a namespace prefix declaration.protected void
handleSolutionImpl(BindingSet bindingSet)
Extending classes must implement this method instead of overridingAbstractQueryResultWriter.handleSolution(BindingSet)
in order to benefit from automatic handling of RDF-star encoding.void
handleStylesheet(java.lang.String stylesheetUrl)
Handles a stylesheet URL.void
startDocument()
Indicates the start of the document.void
startHeader()
Indicates the start of the header.void
startQueryResult(java.util.List<java.lang.String> bindingNames)
Indicates the start of a sequence of Solutions.private void
writeBNode(BNode bnode)
private void
writeEmptyRow()
private void
writeLiteral(Literal literal)
private java.lang.Integer
writeNamespace(java.lang.String namespace)
private void
writeNull()
private void
writeQName(IRI uri)
private void
writeRepeat()
private void
writeString(java.lang.String s)
private void
writeTriple(Triple triple)
private void
writeValue(Value value)
-
Methods inherited from class org.eclipse.rdf4j.query.resultio.AbstractQueryResultWriter
getFileFormat, getWriterConfig, handleSolution, setWriterConfig, xsdStringToPlainLiteral
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.query.QueryResultHandler
handleSolution
-
Methods inherited from interface org.eclipse.rdf4j.query.resultio.QueryResultWriter
getWriterConfig, setWriterConfig
-
Methods inherited from interface org.eclipse.rdf4j.common.io.Sink
acceptsFileFormat, getFileFormat
-
-
-
-
Field Detail
-
out
private final java.io.DataOutputStream out
The output stream to write the results table to.
-
charsetEncoder
private final java.nio.charset.CharsetEncoder charsetEncoder
-
namespaceTable
private final java.util.Map<java.lang.String,java.lang.Integer> namespaceTable
Map containing the namespace IDs (Integer objects) that have been defined in the document, stored using the concerning namespace (Strings).
-
nextNamespaceID
private int nextNamespaceID
-
previousBindings
private BindingSet previousBindings
-
bindingNames
private java.util.List<java.lang.String> bindingNames
-
documentStarted
private boolean documentStarted
-
tupleVariablesFound
protected boolean tupleVariablesFound
-
-
Method Detail
-
getOutputStream
public java.io.OutputStream getOutputStream()
Description copied from interface:ByteSink
get theOutputStream
used by thisByteSink
.- Specified by:
getOutputStream
in interfaceByteSink
- Returns:
- an
OutputStream
-
getTupleQueryResultFormat
public final TupleQueryResultFormat getTupleQueryResultFormat()
Description copied from interface:TupleQueryResultWriter
Gets the query result format that this writer uses.- Specified by:
getTupleQueryResultFormat
in interfaceTupleQueryResultWriter
-
getQueryResultFormat
public final TupleQueryResultFormat getQueryResultFormat()
Description copied from interface:QueryResultWriter
Gets the query result format that this writer uses.- Specified by:
getQueryResultFormat
in interfaceQueryResultWriter
-
getSupportedSettings
public java.util.Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettings
in interfaceQueryResultWriter
- Overrides:
getSupportedSettings
in classAbstractQueryResultWriter
- Returns:
- A collection of
RioSetting
s that are supported by thisQueryResultWriter
.
-
startDocument
public void startDocument() throws TupleQueryResultHandlerException
Description copied from interface:QueryResultWriter
Indicates the start of the document.- Specified by:
startDocument
in interfaceQueryResultWriter
- Throws:
TupleQueryResultHandlerException
-
startQueryResult
public void startQueryResult(java.util.List<java.lang.String> bindingNames) throws TupleQueryResultHandlerException
Description copied from interface:QueryResultHandler
Indicates the start of a sequence of Solutions. The supplied bindingNames are an indication of the values that are in the Solutions. For example, a SPARQL query like select ?X ?Y where { ?X ?P ?Y } will have binding names X and Y.- Specified by:
startQueryResult
in interfaceQueryResultHandler
- Overrides:
startQueryResult
in classAbstractQueryResultWriter
- Parameters:
bindingNames
- An ordered set of binding names.- Throws:
TupleQueryResultHandlerException
- If there was an error during the starting of the query result handler. This exception may be thrown if theQueryResultHandler.handleBoolean(boolean)
method was called before this method and the handler cannot process both boolean and tuple results simultaneously.
-
endQueryResult
public void endQueryResult() throws TupleQueryResultHandlerException
Description copied from interface:QueryResultHandler
Indicates the end of a sequence of solutions.- Specified by:
endQueryResult
in interfaceQueryResultHandler
- Throws:
TupleQueryResultHandlerException
- If there was an error during the ending of the query result handler. This exception may be thrown if theQueryResultHandler.handleBoolean(boolean)
method was called before this method and the handler cannot process both boolean and tuple results simultaneously.
-
handleSolutionImpl
protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException
Description copied from class:AbstractQueryResultWriter
Extending classes must implement this method instead of overridingAbstractQueryResultWriter.handleSolution(BindingSet)
in order to benefit from automatic handling of RDF-star encoding.- Overrides:
handleSolutionImpl
in classAbstractQueryResultWriter
- Parameters:
bindingSet
- the solution to handle- Throws:
TupleQueryResultHandlerException
-
writeNull
private void writeNull() throws java.io.IOException
- Throws:
java.io.IOException
-
writeRepeat
private void writeRepeat() throws java.io.IOException
- Throws:
java.io.IOException
-
writeValue
private void writeValue(Value value) throws java.io.IOException
- Throws:
java.io.IOException
-
writeEmptyRow
private void writeEmptyRow() throws java.io.IOException
- Throws:
java.io.IOException
-
handleNamespace
public void handleNamespace(java.lang.String prefix, java.lang.String uri) throws QueryResultHandlerException
Description copied from interface:QueryResultWriter
Handles a namespace prefix declaration. If this is called, it should be called beforeQueryResultWriter.startDocument()
to ensure that it has a document wide effect.NOTE: If the format does not support namespaces, it must silently ignore calls to this method.
- Specified by:
handleNamespace
in interfaceQueryResultWriter
- Parameters:
prefix
- The prefix to use for the namespaceuri
- The full URI that is to be represented by the prefix.- Throws:
QueryResultHandlerException
-
writeQName
private void writeQName(IRI uri) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBNode
private void writeBNode(BNode bnode) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLiteral
private void writeLiteral(Literal literal) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTriple
private void writeTriple(Triple triple) throws java.io.IOException
- Throws:
java.io.IOException
-
error
public void error(QueryErrorType errType, java.lang.String msg) throws java.io.IOException
Writes an error msg to the stream.- Parameters:
errType
- The error type.msg
- The error message.- Throws:
java.io.IOException
- When the error could not be written to the stream.
-
writeNamespace
private java.lang.Integer writeNamespace(java.lang.String namespace) throws java.io.IOException
- Throws:
java.io.IOException
-
writeString
private void writeString(java.lang.String s) throws java.io.IOException
- Throws:
java.io.IOException
-
handleStylesheet
public void handleStylesheet(java.lang.String stylesheetUrl) throws QueryResultHandlerException
Description copied from interface:QueryResultWriter
Handles a stylesheet URL. If this is called, it must be called afterQueryResultWriter.startDocument()
and beforeQueryResultWriter.startHeader()
.NOTE: If the format does not support stylesheets, it must silently ignore calls to this method.
- Specified by:
handleStylesheet
in interfaceQueryResultWriter
- Parameters:
stylesheetUrl
- The URL of the stylesheet to be used to style the results.- Throws:
QueryResultHandlerException
- If there was an error handling the stylesheet. This error is not thrown in cases where stylesheets are not supported.
-
startHeader
public void startHeader() throws QueryResultHandlerException
Description copied from interface:QueryResultWriter
Indicates the start of the header.- Specified by:
startHeader
in interfaceQueryResultWriter
- Throws:
QueryResultHandlerException
- If there was an error writing the start of the header.- See Also:
- SPARQL Query Results XML Format documentation for head element.
-
handleLinks
public void handleLinks(java.util.List<java.lang.String> linkUrls) throws QueryResultHandlerException
Description copied from interface:QueryResultHandler
Handles the links elements which are present in SPARQL Results JSON and SPARQL Results XML documents in the header.NOTE: If the format does not support links, it must silently ignore a call to this method.
An accumulating handler should accumulate these links.
- Specified by:
handleLinks
in interfaceQueryResultHandler
- Parameters:
linkUrls
- The URLs of the links to handle.- Throws:
QueryResultHandlerException
- If there was an error handling the set of link URLs. This error is not thrown in cases where links are not supported.- See Also:
- "link"
-
endHeader
public void endHeader() throws QueryResultHandlerException
Description copied from interface:QueryResultWriter
Indicates the end of the header. This must be called afterQueryResultWriter.startHeader()
and before any calls toQueryResultHandler.handleSolution(org.eclipse.rdf4j.query.BindingSet)
.- Specified by:
endHeader
in interfaceQueryResultWriter
- Throws:
QueryResultHandlerException
- If there was an error writing the end of the header.
-
endDocument
private void endDocument() throws java.io.IOException
- Throws:
java.io.IOException
-
handleBoolean
public void handleBoolean(boolean value) throws QueryResultHandlerException
Description copied from interface:QueryResultHandler
Handles the specified boolean value.- Specified by:
handleBoolean
in interfaceQueryResultHandler
- Parameters:
value
- The boolean value to handle.- Throws:
QueryResultHandlerException
- If there was an error during the handling of this value. This exception may be thrown if theQueryResultHandler.startQueryResult(List)
,QueryResultHandler.handleSolution(BindingSet)
orQueryResultHandler.endQueryResult()
methods were called before this method was called, and the handler cannot process both boolean and tuple results simultaneously.
-
-