public class TurtleWriter extends AbstractRDFWriter implements RDFWriter, CharSink
Modifier and Type | Field and Description |
---|---|
protected ParsedIRI |
baseIRI |
protected Model |
bufferedStatements |
protected IRI |
lastWrittenPredicate |
protected Resource |
lastWrittenSubject |
protected boolean |
statementClosed
Flag indicating whether the last written statement has been closed.
|
protected IndentingWriter |
writer |
namespaceTable, statementConsumer
Constructor and Description |
---|
TurtleWriter(OutputStream out)
Creates a new TurtleWriter that will write to the supplied OutputStream.
|
TurtleWriter(OutputStream out,
ParsedIRI baseIRI)
Creates a new TurtleWriter that will write to the supplied OutputStream.
|
TurtleWriter(Writer writer)
Creates a new TurtleWriter that will write to the supplied Writer.
|
TurtleWriter(Writer writer,
ParsedIRI baseIRI)
Creates a new TurtleWriter that will write to the supplied Writer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closePreviousStatement() |
protected void |
consumeStatement(Statement st)
Consume a statement.
|
void |
endRDF()
Signals the end of the RDF data.
|
protected ModelFactory |
getModelFactory() |
RDFFormat |
getRDFFormat()
Gets the RDF format that this RDFWriter uses.
|
Collection<RioSetting<?>> |
getSupportedSettings() |
Writer |
getWriter()
|
void |
handleComment(String comment)
Handles a comment.
|
void |
handleNamespace(String prefix,
String name)
Handles a namespace declaration/definition.
|
protected void |
handleStatementInternal(Statement st,
boolean endRDFCalled,
boolean canShortenSubjectBNode,
boolean canShortenObjectBNode)
Internal method that differentiates between the pretty-print and streaming writer cases.
|
void |
setModelFactory(ModelFactory modelFactory)
Set a
ModelFactory to use for creating internal Models for statement processing/buffering purposes. |
void |
startRDF()
Signals the start of the RDF data.
|
protected void |
writeBase(String baseURI) |
protected void |
writeBNode(BNode bNode)
Deprecated.
Use
writeBNode(BNode, boolean) instead. |
protected void |
writeBNode(BNode bNode,
boolean canShorten) |
protected void |
writeCommentLine(String line) |
protected void |
writeLiteral(Literal lit) |
protected void |
writeNamespace(String prefix,
String name) |
protected void |
writePredicate(IRI predicate) |
protected void |
writeResource(Resource res)
Deprecated.
Use
writeResource(Resource, boolean) instead. |
protected void |
writeResource(Resource res,
boolean canShorten)
|
protected void |
writeStatement(Resource subj,
IRI pred,
Value obj,
Resource context,
boolean canShortenSubjectBNode,
boolean canShortenObjectBNode) |
protected void |
writeTriple(Triple triple,
boolean canShorten) |
protected void |
writeTripleRDFStar(Triple triple,
boolean canShorten) |
protected void |
writeURI(IRI uri) |
protected void |
writeValue(Value val)
Deprecated.
Use
writeValue(Value, boolean) instead. |
protected void |
writeValue(Value val,
boolean canShorten)
|
checkWritingStarted, getFileFormat, getWriterConfig, handleStatement, isWritingStarted, set, setWriterConfig
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getWriterConfig, set, setWriterConfig
handleStatement
acceptsFileFormat, getFileFormat
protected Model bufferedStatements
protected ParsedIRI baseIRI
protected IndentingWriter writer
protected boolean statementClosed
protected Resource lastWrittenSubject
protected IRI lastWrittenPredicate
public TurtleWriter(OutputStream out)
out
- The OutputStream to write the Turtle document to.public TurtleWriter(OutputStream out, ParsedIRI baseIRI)
out
- The OutputStream to write the Turtle document to.baseIRI
- public TurtleWriter(Writer writer)
writer
- The Writer to write the Turtle document to.public RDFFormat getRDFFormat()
RDFWriter
getRDFFormat
in interface RDFWriter
public Collection<RioSetting<?>> getSupportedSettings()
getSupportedSettings
in interface RDFWriter
getSupportedSettings
in class AbstractRDFWriter
RioSetting
s that are supported by this RDFWriter.public void startRDF() throws RDFHandlerException
RDFHandler
startRDF
in interface RDFHandler
startRDF
in class AbstractRDFWriter
RDFHandlerException
- If the RDF handler has encountered an unrecoverable error.public void endRDF() throws RDFHandlerException
RDFHandler
endRDF
in interface RDFHandler
RDFHandlerException
- If the RDF handler has encountered an unrecoverable error.public void handleNamespace(String prefix, String name) throws RDFHandlerException
RDFHandler
handleNamespace
in interface RDFHandler
handleNamespace
in class AbstractRDFWriter
prefix
- The prefix for the namespace, or an empty string in case of a default namespace.name
- The URI that the prefix maps to.RDFHandlerException
- If the RDF handler has encountered an unrecoverable error.public void setModelFactory(ModelFactory modelFactory)
ModelFactory
to use for creating internal Models for statement processing/buffering purposes.modelFactory
- a ModelFactory
to use for internal buffering / statement processing purposes. May not
be null.protected ModelFactory getModelFactory()
protected void consumeStatement(Statement st) throws RDFHandlerException
AbstractRDFWriter
AbstractRDFWriter.handleStatement(Statement)
in order to
benefit from automatic handling of RDF-star conversion or encoding.consumeStatement
in class AbstractRDFWriter
st
- the statement to consume.RDFHandlerException
protected void handleStatementInternal(Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode)
st
- The next statement to writeendRDFCalled
- True if endRDF has been called before this method is called. This is used to buffer
statements for pretty-printing before dumping them when all statements have been
delivered to us.canShortenSubjectBNode
- True if, in the current context, we may be able to shorten the subject of this
statement iff it is an instance of BNode
.canShortenObjectBNode
- True if, in the current context, we may be able to shorten the object of this
statement iff it is an instance of BNode
.protected void writeStatement(Resource subj, IRI pred, Value obj, Resource context, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) throws IOException
IOException
public void handleComment(String comment) throws RDFHandlerException
RDFHandler
handleComment
in interface RDFHandler
comment
- The comment.RDFHandlerException
- If the RDF handler has encountered an unrecoverable error.protected void writeCommentLine(String line) throws IOException
IOException
protected void writeBase(String baseURI) throws IOException
IOException
protected void writeNamespace(String prefix, String name) throws IOException
IOException
protected void writePredicate(IRI predicate) throws IOException
IOException
@Deprecated protected void writeValue(Value val) throws IOException
writeValue(Value, boolean)
instead.val
- The Value
to write.IOException
protected void writeValue(Value val, boolean canShorten) throws IOException
IRI
and has a namespace definition that is suitable
for use in this context for shortening or a BNode
that has been confirmed to be able to be shortened in
this context.val
- The Value
to write.canShorten
- True if, in the current context, we can shorten this value if it is an instance of
BNode
.IOException
@Deprecated protected void writeResource(Resource res) throws IOException
writeResource(Resource, boolean)
instead.res
- The Resource
to write.IOException
protected void writeResource(Resource res, boolean canShorten) throws IOException
Resource
, optionally shortening it if it is an IRI
and has a namespace definition that
is suitable for use in this context for shortening or a BNode
that has been confirmed to be able to be
shortened in this context.res
- The Resource
to write.canShorten
- True if, in the current context, we can shorten this value if it is an instance of
BNode
.IOException
protected void writeURI(IRI uri) throws IOException
IOException
@Deprecated protected void writeBNode(BNode bNode) throws IOException
writeBNode(BNode, boolean)
instead.bNode
- The BNode
to write.IOException
protected void writeBNode(BNode bNode, boolean canShorten) throws IOException
IOException
protected void writeTriple(Triple triple, boolean canShorten) throws IOException
IOException
protected void writeTripleRDFStar(Triple triple, boolean canShorten) throws IOException
IOException
protected void writeLiteral(Literal lit) throws IOException
IOException
protected void closePreviousStatement() throws IOException
IOException
Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.