Class TurtleWriter

java.lang.Object
com.stardog.stark.io.turtle.TurtleWriter
All Implemented Interfaces:
RDFHandler, RDFWriter
Direct Known Subclasses:
PrettyTurtleWriter, TrigWriter

public class TurtleWriter extends Object implements RDFWriter

Default implementation of a writer for Turtle

Since:
1.0
Version:
1.0
Author:
Michael Grove
See Also:
  • Field Details

    • mWriter

      protected final com.stardog.common.io.block.BlockWriter mWriter
    • mOptions

      protected final Options mOptions
    • mNamespaces

      protected final Map<String,String> mNamespaces
    • mStarted

      protected boolean mStarted
    • mStmtClosed

      protected boolean mStmtClosed
    • mLastWrittenSubject

      protected Resource mLastWrittenSubject
    • mLastWrittenPredicate

      protected IRI mLastWrittenPredicate
    • mBlockSpec

      protected com.stardog.common.io.block.BlockSpec mBlockSpec
  • Constructor Details

  • Method Details

    • comment

      public void comment(@Nonnull String theComment)
      Write a comment to the output. Writing need not be started at this point; comments can be written prior to any actual serialized RDF
      Specified by:
      comment in interface RDFWriter
      Parameters:
      theComment - the comment to write
    • writeCommentLine

      protected void writeCommentLine(@Nonnull String theLine)
    • start

      public void start()
      Signals that the RDF writing process is starting.
      Specified by:
      start in interface RDFHandler
      Specified by:
      start in interface RDFWriter
    • handle

      public void handle(@Nonnull Statement theStmt)
      Description copied from interface: RDFWriter
      Write the given Statement
      Specified by:
      handle in interface RDFHandler
      Specified by:
      handle in interface RDFWriter
      Parameters:
      theStmt - the statement to write
    • end

      public void end()
      Signals the writing process is completed. The underlying InputStream is *not* closed, but the caller should not call additional methods on this writer as that will normally yield syntax errors in the output.
      Specified by:
      end in interface RDFHandler
      Specified by:
      end in interface RDFWriter
    • namespace

      public void namespace(@Nonnull String thePrefix, @Nonnull String theIRI)
      Provide a namespace to the writer. This method can be called before writing has started, in which case, the namespace bindings are buffered and written when appropriate after writing has begun.
      Specified by:
      namespace in interface RDFHandler
      Specified by:
      namespace in interface RDFWriter
      Parameters:
      thePrefix - the namespace prefix
      theIRI - the associated IRI
    • closePreviousStatement

      protected void closePreviousStatement()
    • writeNamespace

      protected void writeNamespace(@Nonnull String thePrefix, @Nonnull String theIRI)
    • writePredicate

      protected void writePredicate(@Nonnull IRI predicate) throws IOException
      Throws:
      IOException
    • writeResource

      protected void writeResource(@Nonnull Resource res) 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.
      Throws:
      IOException - if the write operation to the underlying stream fails
    • writeEmbeddedTriple

      protected void writeEmbeddedTriple(@Nonnull Statement statement) throws IOException
      Throws:
      IOException
    • writeValue

      protected void writeValue(@Nonnull Value theValue) 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:
      theValue - The Value to write.
      Throws:
      IOException - if the write operation to the underlying stream fails
    • writeIRI

      protected void writeIRI(@Nonnull IRI theIRI) throws IOException
      Throws:
      IOException
    • writeBNode

      protected void writeBNode(@Nonnull BNode bNode) throws IOException
      Parameters:
      bNode - The BNode to write.
      Throws:
      IOException - if the write operation to the underlying stream fails
    • writeLiteral

      protected void writeLiteral(@Nonnull Literal theLiteral) throws IOException
      Throws:
      IOException
    • format

      @Nonnull public RDFFormat format()
      The format this writer will serialize output in.
      Specified by:
      format in interface RDFWriter
      Returns:
      the format