Package com.stardog.stark.io.turtle

# 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:
  - `TurtleParser`
  - `RDFFormats.TURTLE`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `TurtleWriter.TurtleWriterFactory`
  `Factory` for creating `TurtleWriter`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected com.stardog.common.io.block.BlockSpec`
  `mBlockSpec`
  `protected IRI`
  `mLastWrittenPredicate`
  `protected Resource`
  `mLastWrittenSubject`
  `protected final Map<String,String>`
  `mNamespaces`
  `protected final Options`
  `mOptions`
  `protected boolean`
  `mStarted`
  `protected boolean`
  `mStmtClosed`
  `protected final com.stardog.common.io.block.BlockWriter`
  `mWriter`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TurtleWriter(OutputStream theWriter, Options theOptions)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `closePreviousStatement()`
  `void`
  `comment(String theComment)`
  Write a comment to the output.
  `void`
  `end()`
  Signals the writing process is completed.
  `RDFFormat`
  `format()`
  The `format` this writer will serialize output in.
  `void`
  `handle(Statement theStmt)`
  Write the given `Statement`
  `void`
  `namespace(String thePrefix, String theIRI)`
  Provide a namespace to the writer.
  `void`
  `start()`
  Signals that the RDF writing process is starting.
  `protected void`
  `writeBNode(BNode bNode)`
  `protected void`
  `writeCommentLine(String theLine)`
  `protected void`
  `writeEmbeddedTriple(Statement statement)`
  `protected void`
  `writeIRI(IRI theIRI)`
  `protected void`
  `writeLiteral(Literal theLiteral)`
  `protected void`
  `writeNamespace(String thePrefix, String theIRI)`
  `protected void`
  `writePredicate(IRI predicate)`
  `protected void`
  `writeResource(Resource res)`
  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.
  `protected void`
  `writeValue(Value theValue)`
  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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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

  - ### TurtleWriter

    public TurtleWriter(OutputStream theWriter, Options theOptions)

- ## 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