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 java.lang.Object implements RDFWriter
Default implementation of a
writerfor 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 classTurtleWriter.TurtleWriterFactoryFactoryfor creatingTurtleWriter
-
Field Summary
Fields Modifier and Type Field Description protected com.stardog.common.io.block.BlockSpecmBlockSpecprotected IRImLastWrittenPredicateprotected ResourcemLastWrittenSubjectprotected java.util.Map<java.lang.String,java.lang.String>mNamespacesprotected OptionsmOptionsprotected booleanmStartedprotected booleanmStmtClosedprotected com.stardog.common.io.block.BlockWritermWriter
-
Constructor Summary
Constructors Constructor Description TurtleWriter(java.io.OutputStream theWriter, Options theOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclosePreviousStatement()voidcomment(java.lang.String theComment)Write a comment to the output.voidend()Signals the writing process is completed.RDFFormatformat()Theformatthis writer will serialize output in.voidhandle(Statement theStmt)Write the givenStatementvoidnamespace(java.lang.String thePrefix, java.lang.String theIRI)Provide a namespace to the writer.voidstart()Signals that the RDF writing process is starting.protected voidwriteBNode(BNode bNode)protected voidwriteCommentLine(java.lang.String theLine)protected voidwriteEmbeddedTriple(Statement statement)protected voidwriteIRI(IRI theIRI)protected voidwriteLiteral(Literal theLiteral)protected voidwriteNamespace(java.lang.String thePrefix, java.lang.String theIRI)protected voidwritePredicate(IRI predicate)protected voidwriteResource(Resource res)protected voidwriteValue(Value theValue)
-
-
-
Field Detail
-
mWriter
protected final com.stardog.common.io.block.BlockWriter mWriter
-
mOptions
protected final Options mOptions
-
mNamespaces
protected final java.util.Map<java.lang.String,java.lang.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 Detail
-
TurtleWriter
public TurtleWriter(java.io.OutputStream theWriter, Options theOptions)
-
-
Method Detail
-
comment
public void comment(@Nonnull java.lang.String theComment)Write a comment to the output. Writing need not bestartedat this point; comments can be written prior to any actual serialized RDF
-
writeCommentLine
protected void writeCommentLine(@Nonnull java.lang.String theLine)
-
start
public void start()
Signals that the RDF writing process is starting.- Specified by:
startin interfaceRDFHandler- Specified by:
startin interfaceRDFWriter
-
handle
public void handle(@Nonnull Statement theStmt)Description copied from interface:RDFWriterWrite the givenStatement- Specified by:
handlein interfaceRDFHandler- Specified by:
handlein interfaceRDFWriter- Parameters:
theStmt- the statement to write
-
end
public void end()
Signals the writing process is completed. The underlyingInputStreamis *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:
endin interfaceRDFHandler- Specified by:
endin interfaceRDFWriter
-
namespace
public void namespace(@Nonnull java.lang.String thePrefix, @Nonnull java.lang.String theIRI)Provide a namespace to the writer. This method can be called before writing hasstarted, in which case, the namespace bindings are buffered and written when appropriate after writing has begun.- Specified by:
namespacein interfaceRDFHandler- Specified by:
namespacein interfaceRDFWriter- Parameters:
thePrefix- the namespace prefixtheIRI- the associated IRI
-
closePreviousStatement
protected void closePreviousStatement()
-
writeNamespace
protected void writeNamespace(@Nonnull java.lang.String thePrefix, @Nonnull java.lang.String theIRI)
-
writePredicate
protected void writePredicate(@Nonnull IRI predicate) throws java.io.IOException- Throws:
java.io.IOException
-
writeResource
protected void writeResource(@Nonnull Resource res) throws java.io.IOExceptionWrites aResource, optionally shortening it if it is anIRIand has a namespace definition that is suitable for use in this context for shortening or aBNodethat has been confirmed to be able to be shortened in this context.- Parameters:
res- TheResourceto write.- Throws:
java.io.IOException- if the write operation to the underlying stream fails
-
writeEmbeddedTriple
protected void writeEmbeddedTriple(@Nonnull Statement statement) throws java.io.IOException- Throws:
java.io.IOException
-
writeValue
protected void writeValue(@Nonnull Value theValue) throws java.io.IOExceptionWrites a value, optionally shortening it if it is anIRIand has a namespace definition that is suitable for use in this context for shortening or aBNodethat has been confirmed to be able to be shortened in this context.- Parameters:
theValue- TheValueto write.- Throws:
java.io.IOException- if the write operation to the underlying stream fails
-
writeIRI
protected void writeIRI(@Nonnull IRI theIRI) throws java.io.IOException- Throws:
java.io.IOException
-
writeBNode
protected void writeBNode(@Nonnull BNode bNode) throws java.io.IOException- Parameters:
bNode- TheBNodeto write.- Throws:
java.io.IOException- if the write operation to the underlying stream fails
-
writeLiteral
protected void writeLiteral(@Nonnull Literal theLiteral) throws java.io.IOException- Throws:
java.io.IOException
-
-