Class 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 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:
        getWriter in interface org.eclipse.rdf4j.common.io.CharSink
      • setModelFactory

        public void setModelFactory​(org.eclipse.rdf4j.model.ModelFactory modelFactory)
        Set a ModelFactory to use for creating internal Models for statement processing/buffering purposes.
        Parameters:
        modelFactory - a ModelFactory to use for internal buffering / statement processing purposes. May not be null.
      • getModelFactory

        protected org.eclipse.rdf4j.model.ModelFactory getModelFactory()
      • 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 write
        endRDFCalled - 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.
      • 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
      • writePredicate

        protected void writePredicate​(org.eclipse.rdf4j.model.IRI predicate)
                               throws IOException
        Throws:
        IOException
      • writeValue

        protected void writeValue​(org.eclipse.rdf4j.model.Value val,
                                  boolean canShorten)
                           throws IOException
        Writes a value, 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.
        Parameters:
        val - The Value to write.
        canShorten - True if, in the current context, we can shorten this value if it is an instance of BNode .
        Throws:
        IOException
      • writeResource

        protected void writeResource​(org.eclipse.rdf4j.model.Resource res,
                                     boolean canShorten)
                              throws IOException
        Writes a 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.
        Parameters:
        res - The Resource to write.
        canShorten - True if, in the current context, we can shorten this value if it is an instance of BNode .
        Throws:
        IOException
      • writeURI

        protected void writeURI​(org.eclipse.rdf4j.model.IRI uri)
                         throws IOException
        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