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:
    RDFHandler, RDFWriter
  Direct Known Subclasses:
    TriGWriter

      public class TurtleWriter
      extends AbstractRDFWriter
      implements RDFWriter

  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 and Description
    --- | ---
    `protected ParsedIRI` | `baseIRI`
    `protected IRI` | `lastWrittenPredicate`
    `protected Resource` | `lastWrittenSubject`
    `protected Model` | `prettyPrintModel` Deprecated.
    `protected boolean` | `statementClosed` Flag indicating whether the last written statement has been closed.
    `protected IndentingWriter` | `writer`
    `protected boolean` | `writingStarted`

    - ### Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter

      `namespaceTable`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TurtleWriter(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

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `closePreviousStatement()`
    `void` | `endRDF()` Signals the end of the RDF data.
    `RDFFormat` | `getRDFFormat()` Gets the RDF format that this RDFWriter uses.
    `void` | `handleComment(String comment)` Handles a comment.
    `void` | `handleNamespace(String prefix, String name)` Handles a namespace declaration/definition.
    `void` | `handleStatement(Statement st)` Handles a statement.
    `protected void` | `handleStatementInternal(Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode)` Internal method that differentiates between the pretty-print and streaming writer cases.
    `void` | `startRDF()` Signals the start of the RDF data.
    `protected void` | `writeBase(String baseURI)`
    `protected void` | `writeBNode(BNode bNode)` Deprecated. Use `writeBNode(BNode, boolean)` instead.
    `protected void` | `writeBNode(BNode bNode, boolean canShorten)`
    `protected void` | `writeCommentLine(String line)`
    `protected void` | `writeLiteral(Literal lit)`
    `protected void` | `writeNamespace(String prefix, String name)`
    `protected void` | `writePredicate(IRI predicate)`
    `protected void` | `writeResource(Resource res)` Deprecated. Use `writeResource(Resource, boolean)` instead.
    `protected void` | `writeResource(Resource res, boolean canShorten)` 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` | `writeURI(IRI uri)`
    `protected void` | `writeValue(Value val)` Deprecated. Use `writeValue(Value, boolean)` instead.
    `protected void` | `writeValue(Value val, boolean canShorten)` 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 org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter

      `getSupportedSettings, getWriterConfig, set, setWriterConfig`

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

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

    - ### Methods inherited from interface org.eclipse.rdf4j.rio.RDFWriter

      `getSupportedSettings, getWriterConfig, set, setWriterConfig`

- - ### Field Detail

    - #### baseIRI

          protected ParsedIRI baseIRI

    - #### writer

          protected IndentingWriter writer

    - #### writingStarted

          protected boolean writingStarted

    - #### statementClosed

          protected boolean statementClosed

      Flag indicating whether the last written statement has been closed.

    - #### lastWrittenSubject

          protected Resource lastWrittenSubject

    - #### lastWrittenPredicate

          protected IRI lastWrittenPredicate

    - #### prettyPrintModel

          @Deprecated
          protected Model prettyPrintModel

      Deprecated.
      Always null

  - ### 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,
                              ParsedIRI baseIRI)

      Creates a new TurtleWriter that will write to the supplied OutputStream.
      Parameters:
        `out` - The OutputStream to write the Turtle document to.

    - #### 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,
                              ParsedIRI baseIRI)

      Creates a new TurtleWriter that will write to the supplied Writer.
      Parameters:
        `writer` - The Writer to write the Turtle document to.

  - ### Method Detail

    - #### getRDFFormat

          public RDFFormat getRDFFormat()

      Description copied from interface: `RDFWriter`
      Gets the RDF format that this RDFWriter uses.
      Specified by:
        `getRDFFormat` in interface `RDFWriter`

    - #### startRDF

          public void startRDF()
                        throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Signals the start of the RDF data. This method is called before any data is reported.
      Specified by:
        `startRDF` in interface `RDFHandler`
      Throws:
        `RDFHandlerException` - If the RDF handler has encountered an unrecoverable error.

    - #### endRDF

          public void endRDF()
                      throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Signals the end of the RDF data. This method is called when all data has been reported.
      Specified by:
        `endRDF` in interface `RDFHandler`
      Throws:
        `RDFHandlerException` - If the RDF handler has encountered an unrecoverable error.

    - #### handleNamespace

          public void handleNamespace(String prefix,
                                      String name)
                               throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Handles 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:
        `handleNamespace` in interface `RDFHandler`
      Overrides:
        `handleNamespace` in class `AbstractRDFWriter`
      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.

    - #### handleStatement

          public void handleStatement(Statement st)
                               throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Handles a statement.
      Specified by:
        `handleStatement` in interface `RDFHandler`
      Parameters:
        `st` - The statement.
      Throws:
        `RDFHandlerException` - If the RDF handler has encountered an unrecoverable error.

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

    - #### handleComment

          public void handleComment(String comment)
                             throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Handles a comment.
      Specified by:
        `handleComment` in interface `RDFHandler`
      Parameters:
        `comment` - The comment.
      Throws:
        `RDFHandlerException` - If the RDF handler has encountered an unrecoverable error.

    - #### 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(IRI predicate)
                                 throws IOException

      Throws:
        `IOException`

    - #### writeValue

          @Deprecated
          protected void writeValue(Value val)
                                         throws IOException

      Deprecated. Use `writeValue(Value, boolean)` instead.
      Parameters:
        `val` - The `Value` to write.
      Throws:
        `IOException`

    - #### writeValue

          protected void writeValue(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

          @Deprecated
          protected void writeResource(Resource res)
                                            throws IOException

      Deprecated. Use `writeResource(Resource, boolean)` instead.
      Parameters:
        `res` - The `Resource` to write.
      Throws:
        `IOException`

    - #### writeResource

          protected void writeResource(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(IRI uri)
                           throws IOException

      Throws:
        `IOException`

    - #### writeBNode

          @Deprecated
          protected void writeBNode(BNode bNode)
                                         throws IOException

      Deprecated. Use `writeBNode(BNode, boolean)` instead.
      Parameters:
        `bNode` - The `BNode` to write.
      Throws:
        `IOException`

    - #### writeBNode

          protected void writeBNode(BNode bNode,
                                    boolean canShorten)
                             throws IOException

      Throws:
        `IOException`

    - #### writeLiteral

          protected void writeLiteral(Literal lit)
                               throws IOException

      Throws:
        `IOException`

    - #### closePreviousStatement

          protected void closePreviousStatement()
                                         throws IOException

      Throws:
        `IOException`

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.