org.openrdf.rio.turtle
Class TurtleWriter

java.lang.Object
  extended by org.openrdf.rio.turtle.TurtleWriter
All Implemented Interfaces:
RDFHandler, RDFWriter
Direct Known Subclasses:
TriGWriter

public class TurtleWriter
extends Object
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
protected  URI lastWrittenPredicate
           
protected  Resource lastWrittenSubject
           
protected  Map<String,String> namespaceTable
          Table mapping namespace names (key) to namespace prefixes (value).
protected  boolean statementClosed
          Flag indicating whether the last written statement has been closed.
protected  IndentingWriter writer
           
protected  boolean writingStarted
           
 
Constructor Summary
TurtleWriter(OutputStream out)
          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.
 
Method Summary
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.
 void startRDF()
          Signals the start of the RDF data.
protected  void writeBNode(BNode bNode)
           
protected  void writeCommentLine(String line)
           
protected  void writeLiteral(Literal lit)
           
protected  void writeNamespace(String prefix, String name)
           
protected  void writePredicate(URI predicate)
           
protected  void writeResource(Resource res)
           
protected  void writeURI(URI uri)
           
protected  void writeValue(Value val)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected IndentingWriter writer

namespaceTable

protected Map<String,String> namespaceTable
Table mapping namespace names (key) to namespace prefixes (value).


writingStarted

protected boolean writingStarted

statementClosed

protected boolean statementClosed
Flag indicating whether the last written statement has been closed.


lastWrittenSubject

protected Resource lastWrittenSubject

lastWrittenPredicate

protected URI 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(Writer writer)
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
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.

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

writeNamespace

protected void writeNamespace(String prefix,
                              String name)
                       throws IOException
Throws:
IOException

writePredicate

protected void writePredicate(URI predicate)
                       throws IOException
Throws:
IOException

writeValue

protected void writeValue(Value val)
                   throws IOException
Throws:
IOException

writeResource

protected void writeResource(Resource res)
                      throws IOException
Throws:
IOException

writeURI

protected void writeURI(URI uri)
                 throws IOException
Throws:
IOException

writeBNode

protected void writeBNode(BNode bNode)
                   throws IOException
Throws:
IOException

writeLiteral

protected void writeLiteral(Literal lit)
                     throws IOException
Throws:
IOException

closePreviousStatement

protected void closePreviousStatement()
                               throws IOException
Throws:
IOException


Copyright © 2001-2012 Aduna. All Rights Reserved.