Class RDFWriter

java.lang.Object
org.apache.jena.riot.RDFWriter

public class RDFWriter extends Object
An RDFWriter is a process that will output triples or quads in an RDF syntax. RDFWriterBuilder provides the means to setup the writer.

The process is

    DatasetGraph dsg = ...
    RDFWriter writer = RDFWriter.create().source(dsg).lang(Lang.TTL).build();
    OutputStream out =
    writer.output(out);
 
or using abbreviated forms:
    RDFWriter.create().source(dsg).lang(Lang.TTL).output(out);
 
See Also:
  • Method Details

    • create

      public static RDFWriterBuilder create()
      Create an RDFWriterBuilder.

      Often used in a pattern such as:

          RDFWriter.create()
              .lang(Lang.TTL)
              .source(graph)
              .output(System.out);
       
    • source

      public static RDFWriterBuilder source(org.apache.jena.graph.Graph graph)
      Create an RDFWriterBuilder and set the source of writing to the graph argument.
      Parameters:
      graph - A Graph.
      Returns:
      RDFWriterBuilder
    • source

      public static RDFWriterBuilder source(org.apache.jena.rdf.model.Model model)
      Create an RDFWriterBuilder and set the source of writing to the graph argument.
      Parameters:
      model - A Model.
      Returns:
      RDFWriterBuilder
    • source

      public static RDFWriterBuilder source(DatasetGraph dataset)
      Create an RDFWriterBuilder and set the source of writing to the graph argument.
      Parameters:
      dataset - A DatasetGraph.
      Returns:
      RDFWriterBuilder
    • source

      public static RDFWriterBuilder source(Dataset dataset)
      Create an RDFWriterBuilder and set the source of writing to the graph argument.
      Parameters:
      dataset - A Dataset.
      Returns:
      RDFWriterBuilder
    • asString

      public String asString()
      Write and return the output as a string.

      The Lang or RDFFormat must have been set.

    • toString

      public String toString()
      Write and return the output as a string. This is the same as asString().

      The Lang or RDFFormat must have been set.

      Overrides:
      toString in class Object
    • output

      public void output(OutputStream output)
      Write the source to the OutputStream.

      The Lang or RDFFormat must have been set.

      Parameters:
      output -
    • output

      @Deprecated public void output(Writer javaWriter)
      Deprecated.
      Using Java Writers risks corruption because of mismatch of character set. Only UTF-8 is safe.
      Write the source to the Java Writer.

      The Lang or RDFFormat must have been set.

      Parameters:
      javaWriter -
    • output

      public void output(StringWriter javaWriter)
      Write the source to a Java StringWriter.

      The Lang or RDFFormat must have been set.

      Parameters:
      javaWriter -
    • output

      public void output(String filename)
      Write the source to the file.

      If neither Lang nor RDFFormat are set, an attempt to guess an RDF Syntax is made from the file extension.

      Output to "-" goes to stdout.

      Parameters:
      filename -