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
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 class
TurtleWriter.TurtleWriterFactory
Factory
for creatingTurtleWriter
-
Field Summary
Fields Modifier and Type Field Description protected com.stardog.common.io.block.BlockSpec
mBlockSpec
protected IRI
mLastWrittenPredicate
protected Resource
mLastWrittenSubject
protected java.util.Map<java.lang.String,java.lang.String>
mNamespaces
protected Options
mOptions
protected boolean
mStarted
protected boolean
mStmtClosed
protected com.stardog.common.io.block.BlockWriter
mWriter
-
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 void
closePreviousStatement()
void
comment(java.lang.String theComment)
Write a comment to the output.void
end()
Signals the writing process is completed.RDFFormat
format()
Theformat
this writer will serialize output in.void
handle(Statement theStmt)
Write the givenStatement
void
namespace(java.lang.String thePrefix, java.lang.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(java.lang.String theLine)
protected void
writeEmbeddedTriple(Statement statement)
protected void
writeIRI(IRI theIRI)
protected void
writeLiteral(Literal theLiteral)
protected void
writeNamespace(java.lang.String thePrefix, java.lang.String theIRI)
protected void
writePredicate(IRI predicate)
protected void
writeResource(Resource res)
protected void
writeValue(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 bestarted
at 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:
start
in interfaceRDFHandler
- Specified by:
start
in interfaceRDFWriter
-
handle
public void handle(@Nonnull Statement theStmt)
Description copied from interface:RDFWriter
Write the givenStatement
- Specified by:
handle
in interfaceRDFHandler
- Specified by:
handle
in interfaceRDFWriter
- Parameters:
theStmt
- the statement to write
-
end
public void end()
Signals the writing process is completed. The underlyingInputStream
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 interfaceRDFHandler
- Specified by:
end
in 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:
namespace
in interfaceRDFHandler
- Specified by:
namespace
in 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.IOException
Writes aResource
, optionally shortening it if it is anIRI
and has a namespace definition that is suitable for use in this context for shortening or aBNode
that has been confirmed to be able to be shortened in this context.- Parameters:
res
- TheResource
to 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.IOException
Writes a value, optionally shortening it if it is anIRI
and has a namespace definition that is suitable for use in this context for shortening or aBNode
that has been confirmed to be able to be shortened in this context.- Parameters:
theValue
- TheValue
to 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
- TheBNode
to 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
-
-