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:
org.eclipse.rdf4j.common.io.CharSink,org.eclipse.rdf4j.common.io.Sink,RDFHandler,RDFWriter
- Direct Known Subclasses:
TurtleStarWriter
public class TurtleWriter extends AbstractRDFWriter implements org.eclipse.rdf4j.common.io.CharSink
An implementation of the RDFWriter interface that writes RDF documents in Turtle format. The Turtle format is defined in in this document.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.eclipse.rdf4j.common.net.ParsedIRIbaseIRIprotected org.eclipse.rdf4j.model.ModelbufferedStatementsprotected org.eclipse.rdf4j.model.IRIlastWrittenPredicateprotected org.eclipse.rdf4j.model.ResourcelastWrittenSubjectprotected booleanstatementClosedFlag indicating whether the last written statement has been closed.protected org.eclipse.rdf4j.common.io.IndentingWriterwriter-
Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
namespaceTable, statementConsumer
-
-
Constructor Summary
Constructors Constructor Description TurtleWriter(OutputStream out)Creates a new TurtleWriter that will write to the supplied OutputStream.TurtleWriter(OutputStream out, org.eclipse.rdf4j.common.net.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, org.eclipse.rdf4j.common.net.ParsedIRI baseIRI)Creates a new TurtleWriter that will write to the supplied Writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidclosePreviousStatement()protected voidconsumeStatement(org.eclipse.rdf4j.model.Statement st)voidendRDF()protected org.eclipse.rdf4j.model.ModelFactorygetModelFactory()RDFFormatgetRDFFormat()Collection<RioSetting<?>>getSupportedSettings()WritergetWriter()voidhandleComment(String comment)voidhandleNamespace(String prefix, String name)protected voidhandleStatementInternal(org.eclipse.rdf4j.model.Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode)Internal method that differentiates between the pretty-print and streaming writer cases.voidsetModelFactory(org.eclipse.rdf4j.model.ModelFactory modelFactory)Set aModelFactoryto use for creating internal Models for statement processing/buffering purposes.voidstartRDF()protected voidwriteBase(String baseURI)protected voidwriteBNode(org.eclipse.rdf4j.model.BNode bNode)Deprecated.UsewriteBNode(BNode, boolean)instead.protected voidwriteBNode(org.eclipse.rdf4j.model.BNode bNode, boolean canShorten)protected voidwriteCommentLine(String line)protected voidwriteLiteral(org.eclipse.rdf4j.model.Literal lit)protected voidwriteNamespace(String prefix, String name)protected voidwritePredicate(org.eclipse.rdf4j.model.IRI predicate)protected voidwriteResource(org.eclipse.rdf4j.model.Resource res)Deprecated.UsewriteResource(Resource, boolean)instead.protected voidwriteResource(org.eclipse.rdf4j.model.Resource res, boolean canShorten)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.protected voidwriteStatement(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, org.eclipse.rdf4j.model.Resource context, boolean canShortenSubjectBNode, boolean canShortenObjectBNode)protected voidwriteTriple(org.eclipse.rdf4j.model.Triple triple, boolean canShorten)protected voidwriteTripleRDFStar(org.eclipse.rdf4j.model.Triple triple, boolean canShorten)protected voidwriteURI(org.eclipse.rdf4j.model.IRI uri)protected voidwriteValue(org.eclipse.rdf4j.model.Value val)Deprecated.UsewriteValue(Value, boolean)instead.protected voidwriteValue(org.eclipse.rdf4j.model.Value val, boolean canShorten)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.-
Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
checkWritingStarted, getFileFormat, getWriterConfig, handleStatement, isWritingStarted, set, setWriterConfig
-
-
-
-
Field Detail
-
bufferedStatements
protected org.eclipse.rdf4j.model.Model bufferedStatements
-
baseIRI
protected org.eclipse.rdf4j.common.net.ParsedIRI baseIRI
-
writer
protected org.eclipse.rdf4j.common.io.IndentingWriter writer
-
statementClosed
protected boolean statementClosed
Flag indicating whether the last written statement has been closed.
-
lastWrittenSubject
protected org.eclipse.rdf4j.model.Resource lastWrittenSubject
-
lastWrittenPredicate
protected org.eclipse.rdf4j.model.IRI lastWrittenPredicate
-
-
Constructor Detail
-
TurtleWriter
public TurtleWriter(OutputStream out)
Creates a new TurtleWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the Turtle document to.
-
TurtleWriter
public TurtleWriter(OutputStream out, org.eclipse.rdf4j.common.net.ParsedIRI baseIRI)
Creates a new TurtleWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the Turtle document to.baseIRI-
-
TurtleWriter
public TurtleWriter(Writer writer)
Creates a new TurtleWriter that will write to the supplied Writer.- Parameters:
writer- The Writer to write the Turtle document to.
-
TurtleWriter
public TurtleWriter(Writer writer, org.eclipse.rdf4j.common.net.ParsedIRI baseIRI)
Creates a new TurtleWriter that will write to the supplied Writer.- Parameters:
writer- The Writer to write the Turtle document to.baseIRI-
-
-
Method Detail
-
getWriter
public Writer getWriter()
- Specified by:
getWriterin interfaceorg.eclipse.rdf4j.common.io.CharSink
-
getRDFFormat
public RDFFormat getRDFFormat()
- Specified by:
getRDFFormatin interfaceRDFWriter
-
getSupportedSettings
public Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettingsin interfaceRDFWriter- Overrides:
getSupportedSettingsin classAbstractRDFWriter
-
startRDF
public void startRDF() throws RDFHandlerException- Specified by:
startRDFin interfaceRDFHandler- Overrides:
startRDFin classAbstractRDFWriter- Throws:
RDFHandlerException
-
endRDF
public void endRDF() throws RDFHandlerException- Specified by:
endRDFin interfaceRDFHandler- Throws:
RDFHandlerException
-
handleNamespace
public void handleNamespace(String prefix, String name) throws RDFHandlerException
- Specified by:
handleNamespacein interfaceRDFHandler- Overrides:
handleNamespacein classAbstractRDFWriter- Throws:
RDFHandlerException
-
setModelFactory
public void setModelFactory(org.eclipse.rdf4j.model.ModelFactory modelFactory)
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
protected org.eclipse.rdf4j.model.ModelFactory getModelFactory()
-
consumeStatement
protected void consumeStatement(org.eclipse.rdf4j.model.Statement st) throws RDFHandlerException- Overrides:
consumeStatementin classAbstractRDFWriter- Throws:
RDFHandlerException
-
handleStatementInternal
protected void handleStatementInternal(org.eclipse.rdf4j.model.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(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, org.eclipse.rdf4j.model.Resource context, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) throws IOException- Throws:
IOException
-
handleComment
public void handleComment(String comment) throws RDFHandlerException
- Specified by:
handleCommentin interfaceRDFHandler- Throws:
RDFHandlerException
-
writeCommentLine
protected void writeCommentLine(String line) throws IOException
- Throws:
IOException
-
writeBase
protected void writeBase(String baseURI) throws IOException
- Throws:
IOException
-
writeNamespace
protected void writeNamespace(String prefix, String name) throws IOException
- Throws:
IOException
-
writePredicate
protected void writePredicate(org.eclipse.rdf4j.model.IRI predicate) throws IOException- Throws:
IOException
-
writeValue
@Deprecated protected void writeValue(org.eclipse.rdf4j.model.Value val) throws IOException
Deprecated.UsewriteValue(Value, boolean)instead.- Parameters:
val- TheValueto write.- Throws:
IOException
-
writeValue
protected void writeValue(org.eclipse.rdf4j.model.Value val, boolean canShorten) throws IOExceptionWrites 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 protected void writeResource(org.eclipse.rdf4j.model.Resource res) throws IOException
Deprecated.UsewriteResource(Resource, boolean)instead.- Parameters:
res- TheResourceto write.- Throws:
IOException
-
writeResource
protected void writeResource(org.eclipse.rdf4j.model.Resource res, boolean canShorten) throws IOExceptionWrites 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
protected void writeURI(org.eclipse.rdf4j.model.IRI uri) throws IOException- Throws:
IOException
-
writeBNode
@Deprecated protected void writeBNode(org.eclipse.rdf4j.model.BNode bNode) throws IOException
Deprecated.UsewriteBNode(BNode, boolean)instead.- Parameters:
bNode- TheBNodeto write.- Throws:
IOException
-
writeBNode
protected void writeBNode(org.eclipse.rdf4j.model.BNode bNode, boolean canShorten) throws IOException- Throws:
IOException
-
writeTriple
protected void writeTriple(org.eclipse.rdf4j.model.Triple triple, boolean canShorten) throws IOException- Throws:
IOException
-
writeTripleRDFStar
protected void writeTripleRDFStar(org.eclipse.rdf4j.model.Triple triple, boolean canShorten) throws IOException- Throws:
IOException
-
writeLiteral
protected void writeLiteral(org.eclipse.rdf4j.model.Literal lit) throws IOException- Throws:
IOException
-
closePreviousStatement
protected void closePreviousStatement() throws IOException- Throws:
IOException
-
-