Package org.eclipse.rdf4j.rio.turtle
Class TurtleWriter
java.lang.Object
org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
org.eclipse.rdf4j.rio.turtle.TurtleWriter
- All Implemented Interfaces:
CharSink,Sink,RDFHandler,RDFWriter
- Direct Known Subclasses:
TriGWriter,TurtleStarWriter
An implementation of the RDFWriter interface that writes RDF documents in Turtle format. The Turtle format is defined
in in this document.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ParsedIRIprotected Modelprotected IRIprotected Resourceprotected booleanFlag indicating whether the last written statement has been closed.protected IndentingWriterFields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
namespaceTable, statementConsumer -
Constructor Summary
ConstructorsConstructorDescriptionTurtleWriter(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidConsume a statement.voidendRDF()Signals the end of the RDF data.protected ModelFactoryGets the RDF format that this RDFWriter uses.Collection<RioSetting<?>>voidhandleComment(String comment) Handles a comment.voidhandleNamespace(String prefix, String name) Handles a namespace declaration/definition.protected voidhandleStatementInternal(Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) Internal method that differentiates between the pretty-print and streaming writer cases.voidsetModelFactory(ModelFactory modelFactory) Set aModelFactoryto use for creating internal Models for statement processing/buffering purposes.voidstartRDF()Signals the start of the RDF data.protected voidprotected voidwriteBNode(BNode bNode) Deprecated.protected voidwriteBNode(BNode bNode, boolean canShorten) protected voidwriteCommentLine(String line) protected voidwriteLiteral(Literal lit) protected voidwriteNamespace(String prefix, String name) protected voidwritePredicate(IRI predicate) protected voidwriteResource(Resource res) Deprecated.UsewriteResource(Resource, boolean)instead.protected voidwriteResource(Resource res, boolean canShorten) protected voidwriteStatement(Resource subj, IRI pred, Value obj, Resource context, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) protected voidwriteTriple(Triple triple, boolean canShorten) protected voidwriteTripleRDFStar(Triple triple, boolean canShorten) protected voidprotected voidwriteValue(Value val) Deprecated.UsewriteValue(Value, boolean)instead.protected voidwriteValue(Value val, boolean canShorten) Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
checkWritingStarted, getFileFormat, getWriterConfig, handleStatement, isWritingStarted, set, setWriterConfigMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.rdf4j.common.io.Sink
acceptsFileFormat, getFileFormat
-
Field Details
-
bufferedStatements
-
baseIRI
-
writer
-
statementClosed
protected boolean statementClosedFlag indicating whether the last written statement has been closed. -
lastWrittenSubject
-
lastWrittenPredicate
-
-
Constructor Details
-
TurtleWriter
Creates a new TurtleWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the Turtle document to.
-
TurtleWriter
Creates a new TurtleWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the Turtle document to.baseIRI-
-
TurtleWriter
Creates a new TurtleWriter that will write to the supplied Writer.- Parameters:
writer- The Writer to write the Turtle document to.
-
TurtleWriter
Creates a new TurtleWriter that will write to the supplied Writer.- Parameters:
writer- The Writer to write the Turtle document to.baseIRI-
-
-
Method Details
-
getWriter
Description copied from interface:CharSink -
getRDFFormat
Description copied from interface:RDFWriterGets the RDF format that this RDFWriter uses.- Specified by:
getRDFFormatin interfaceRDFWriter
-
getSupportedSettings
- Specified by:
getSupportedSettingsin interfaceRDFWriter- Overrides:
getSupportedSettingsin classAbstractRDFWriter- Returns:
- A collection of
RioSettings that are supported by this RDFWriter.
-
startRDF
Description copied from interface:RDFHandlerSignals the start of the RDF data. This method is called before any data is reported.- Specified by:
startRDFin interfaceRDFHandler- Overrides:
startRDFin classAbstractRDFWriter- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
endRDF
Description copied from interface:RDFHandlerSignals the end of the RDF data. This method is called when all data has been reported.- Specified by:
endRDFin interfaceRDFHandler- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
handleNamespace
Description copied from interface:RDFHandlerHandles a namespace declaration/definition. A namespace declaration associates a (short) prefix string with the namespace's URI. The prefix for default namespaces, which do not have an associated prefix, are represented as empty strings.- Specified by:
handleNamespacein interfaceRDFHandler- Overrides:
handleNamespacein classAbstractRDFWriter- Parameters:
prefix- The prefix for the namespace, or an empty string in case of a default namespace.name- The URI that the prefix maps to.- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
setModelFactory
Set aModelFactoryto use for creating internal Models for statement processing/buffering purposes.- Parameters:
modelFactory- aModelFactoryto use for internal buffering / statement processing purposes. May not be null.
-
getModelFactory
-
consumeStatement
Description copied from class:AbstractRDFWriterConsume a statement.Extending classes must override this method instead of overriding
AbstractRDFWriter.handleStatement(Statement)in order to benefit from automatic handling of RDF-star conversion or encoding.- Overrides:
consumeStatementin classAbstractRDFWriter- Parameters:
st- the statement to consume.- Throws:
RDFHandlerException
-
handleStatementInternal
protected void handleStatementInternal(Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) Internal method that differentiates between the pretty-print and streaming writer cases.- Parameters:
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 ofBNode.canShortenObjectBNode- True if, in the current context, we may be able to shorten the object of this statement iff it is an instance ofBNode.
-
writeStatement
protected void writeStatement(Resource subj, IRI pred, Value obj, Resource context, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) throws IOException - Throws:
IOException
-
handleComment
Description copied from interface:RDFHandlerHandles a comment.- Specified by:
handleCommentin interfaceRDFHandler- Parameters:
comment- The comment.- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
writeCommentLine
- Throws:
IOException
-
writeBase
- Throws:
IOException
-
writeNamespace
- Throws:
IOException
-
writePredicate
- Throws:
IOException
-
writeValue
Deprecated.UsewriteValue(Value, boolean)instead.- Parameters:
val- TheValueto write.- Throws:
IOException
-
writeValue
Writes a value, optionally shortening it if it is anIRIand has a namespace definition that is suitable for use in this context for shortening or aBNodethat has been confirmed to be able to be shortened in this context.- Parameters:
val- TheValueto write.canShorten- True if, in the current context, we can shorten this value if it is an instance ofBNode.- Throws:
IOException
-
writeResource
Deprecated.UsewriteResource(Resource, boolean)instead.- Parameters:
res- TheResourceto write.- Throws:
IOException
-
writeResource
Writes aResource, optionally shortening it if it is anIRIand has a namespace definition that is suitable for use in this context for shortening or aBNodethat has been confirmed to be able to be shortened in this context.- Parameters:
res- TheResourceto write.canShorten- True if, in the current context, we can shorten this value if it is an instance ofBNode.- Throws:
IOException
-
writeURI
- Throws:
IOException
-
writeBNode
Deprecated.UsewriteBNode(BNode, boolean)instead.- Parameters:
bNode- TheBNodeto write.- Throws:
IOException
-
writeBNode
- Throws:
IOException
-
writeTriple
- Throws:
IOException
-
writeTripleRDFStar
- Throws:
IOException
-
writeLiteral
- Throws:
IOException
-
closePreviousStatement
- Throws:
IOException
-
writeBNode(BNode, boolean)instead.