Class TriGWriter
java.lang.Object
org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
org.eclipse.rdf4j.rio.turtle.TurtleWriter
org.eclipse.rdf4j.rio.trig.TriGWriter
- All Implemented Interfaces:
CharSink, Sink, RDFHandler, RDFWriter
An extension of
TurtleWriter that writes RDF documents in
TriG format by adding graph scopes to the Turtle
document.- Author:
- Arjohn Kampman
-
Field Summary
Fields inherited from class TurtleWriter
baseIRI, bufferedStatements, lastWrittenPredicate, lastWrittenSubject, statementClosed, writerModifier and TypeFieldDescriptionprotected ParsedIRIprotected Modelprotected IRIprotected Resourceprotected booleanFlag indicating whether the last written statement has been closed.protected IndentingWriterFields inherited from class AbstractRDFWriter
namespaceTable, statementConsumerModifier and TypeFieldDescriptionMapping from namespace prefixes to namespace names. -
Constructor Summary
ConstructorsConstructorDescriptionTriGWriter(OutputStream out) Creates a new TriGWriter that will write to the supplied OutputStream.TriGWriter(OutputStream out, ParsedIRI baseIRI) Creates a new TriGWriter that will write to the supplied OutputStream.TriGWriter(Writer writer) Creates a new TriGWriter that will write to the supplied Writer.TriGWriter(Writer writer, ParsedIRI baseIRI) Creates a new TriGWriter that will write to the supplied Writer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidendRDF()Signals the end of the RDF data.Gets the RDF format that this RDFWriter uses.voidstartRDF()Signals the start of the RDF data.protected voidwriteNamespace(String prefix, String name) protected voidwriteStatement(Resource subj, IRI pred, Value obj, Resource context, boolean canShortenSubject, boolean canShortenObject) protected voidWrites the format-specific version directive to the output stream.Methods inherited from class TurtleWriter
closePreviousStatement, consumeStatement, getModelFactory, getSupportedSettings, getWriter, handleComment, handleNamespace, handleStatementInternal, prepareForVersionAnnouncement, requiresVersionAnnouncement, setModelFactory, writeBase, writeBNode, writeBNode, writeCommentLine, writeLiteral, writePredicate, writeResource, writeResource, writeTriple, writeURI, writeValue, writeValueModifier and TypeMethodDescriptionprotected voidprotected voidConsume a statement.protected ModelFactoryCollection<RioSetting<?>> voidhandleComment(String comment) Handles a comment.voidhandleNamespace(String prefix, String name) Handles a namespace declaration/definition.protected voidhandleStatementInternal(Statement st, boolean endRDFCalled, boolean canShortenSubjectBNode, boolean canShortenObjectBNode) Internal method that differentiates between the pretty-print and streaming writer cases.protected voidCloses any open predicate-object list or blank-node structure before the version directive is written.protected booleanOverride to returntruefor writers where an inline version announcement is mandatory when RDF 1.2-specific features are serialised (Turtle, TriG, N3, N-Triples, N-Quads).voidsetModelFactory(ModelFactory modelFactory) Set aModelFactoryto use for creating internal Models for statement processing/buffering purposes.protected voidprotected voidwriteBNode(BNode bNode) Deprecated.protected voidwriteBNode(BNode bNode, boolean canShorten) protected voidwriteCommentLine(String line) protected voidwriteLiteral(Literal lit) protected voidwritePredicate(IRI predicate) protected voidwriteResource(Resource res) Deprecated.UseTurtleWriter.writeResource(Resource, boolean)instead.protected voidwriteResource(Resource res, boolean canShorten) protected voidwriteTriple(TripleTerm tripleTerm, boolean canShorten) protected voidprotected voidwriteValue(Value val) Deprecated.UseTurtleWriter.writeValue(Value, boolean)instead.protected voidwriteValue(Value val, boolean canShorten) Methods inherited from class AbstractRDFWriter
checkWritingStarted, ensureVersionAnnouncement, getFileFormat, getWriterConfig, handleStatement, isRdf12Feature, isRdf12FeatureDetected, isVersionAnnouncementWritten, isWritingStarted, noteRdf12Feature, set, setWriterConfigModifier and TypeMethodDescriptionprotected voidVerify that writing has started.protected final voidEmits the version announcement if — and only if — all of the following hold: at least one RDF 1.2 feature has been observed (AbstractRDFWriter.noteRdf12Feature(Value...)); the announcement has not been written yet;AbstractRDFWriter.requiresVersionAnnouncement()returnstrue. CallsAbstractRDFWriter.prepareForVersionAnnouncement()before writing to let writers close any open output structure first.Get theFileFormatthis sink uses.Retrieves the current writer configuration as a single object.voidHandles a statement.static booleanReturnstrueif the givenValuerequires an RDF 1.2 version announcement (i.e. it is a triple term or a directional language-tagged literal).protected booleanReturnstrueif at least one RDF 1.2-specific feature has been noted so far.protected booleanReturnstrueif the version announcement has already been written to the output stream.protected booleanSee if writing has startedprotected voidnoteRdf12Feature(Value... values) Records that an RDF 1.2-specific feature was observed invalues.<T> RDFWriterset(RioSetting<T> setting, T value) Set a setting on the writer, and return this writer object to allow chaining.setWriterConfig(WriterConfig config) Sets all supplied writer configuration options.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Sink
acceptsFileFormatModifier and TypeMethodDescriptiondefault booleanacceptsFileFormat(FileFormat format) Check if this Sink accepts the suppliedFileFormat.
-
Constructor Details
-
TriGWriter
Creates a new TriGWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the TriG document to.
-
TriGWriter
Creates a new TriGWriter that will write to the supplied OutputStream.- Parameters:
out- The OutputStream to write the TriG document to.baseIRI-
-
TriGWriter
Creates a new TriGWriter that will write to the supplied Writer.- Parameters:
writer- The Writer to write the TriG document to.
-
TriGWriter
-
-
Method Details
-
getRDFFormat
Description copied from interface:RDFWriterGets the RDF format that this RDFWriter uses.- Specified by:
getRDFFormatin interfaceRDFWriter- Overrides:
getRDFFormatin classTurtleWriter
-
startRDF
Description copied from interface:RDFHandlerSignals the start of the RDF data. This method is called before any data is reported.- Specified by:
startRDFin interfaceRDFHandler- Overrides:
startRDFin classTurtleWriter- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
endRDF
Description copied from interface:RDFHandlerSignals the end of the RDF data. This method is called when all data has been reported.- Specified by:
endRDFin interfaceRDFHandler- Overrides:
endRDFin classTurtleWriter- Throws:
RDFHandlerException- If the RDF handler has encountered an unrecoverable error.
-
writeStatement
protected void writeStatement(Resource subj, IRI pred, Value obj, Resource context, boolean canShortenSubject, boolean canShortenObject) throws IOException - Overrides:
writeStatementin classTurtleWriter- Throws:
IOException
-
writeNamespace
- Overrides:
writeNamespacein classTurtleWriter- Throws:
IOException
-
writeVersionAnnouncement
Description copied from class:AbstractRDFWriterWrites the format-specific version directive to the output stream. Called at most once per document, byAbstractRDFWriter.ensureVersionAnnouncement().Default implementation is a no-op; concrete writers must override this.
- Overrides:
writeVersionAnnouncementin classTurtleWriter- Throws:
RDFHandlerException
-
closeActiveContext
- Throws:
IOException
-
TurtleWriter.writeBNode(BNode, boolean)instead.