Class RDFDataMgr

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

public class RDFDataMgr extends Object

General purpose reader framework for RDF (triples and quads) syntaxes.

  • HTTP Content negotiation
  • File type hint by the extension
  • Application language hint

It also provides a way to lookup names in different locations and to remap URIs to other URIs.

Extensible - a new syntax can be added to the framework.

Operations fall into the following categories:

  • read -- Read data from a location into a Model, Dataset, etc. The methods in this class treat all types of Model in the same way. For behavior specific to a subtype of Model, use the methods of that specific class.
  • loadXXX -- Read data and return an in-memory object holding the data.
  • parse -- Read data and send to an StreamRDF
  • open -- Open a typed input stream to the location, using any alternative locations
  • write -- Write Model/Dataset etc
  • create -- Create a reader or writer explicitly

RDFDataMgr provides single functions for many of the common application patterns. It is built on top of RDFParser for reading and RDFWriter for output. Each of these classes has an associated builder that provides complete control over the parsing process. For example, to translate language tags to lower case on input:

     RDFParser.create()
         .source("myData.ttl")
         .langTagLowerCase()
         .parse(graph);
 
or to have Turtle written with BASE and PREFIX rather than @base and @prefix (both are legal Turtle):
     RDFWriter.create()
         .set(RIOT.symTurtleDirectiveStyle, "rdf11")
         .source(model)
         .output(System.out);
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Iterator<Quad>
    createIteratorQuads(InputStream input, Lang lang, String baseIRI)
    Deprecated, for removal: This API element is subject to removal in a future version.
    static Iterator<org.apache.jena.graph.Triple>
    createIteratorTriples(InputStream input, Lang lang, String baseIRI)
    Deprecated, for removal: This API element is subject to removal in a future version.
    static Lang
    determineLang(String target, String ctStr, Lang hintLang)
    Determine the Lang, given the URI target, any content type header string and a hint
    static Dataset
    Create a memory Dataset and read in some data
    static Dataset
    loadDataset(String uri, Lang lang)
    Create a memory Dataset and read in some data
    Create a memory DatasetGraph and read in some data
    Create a memory DatasetGraph and read in some data
    static org.apache.jena.graph.Graph
    Create a memory Graph and read in some data
    static org.apache.jena.graph.Graph
    loadGraph(String uri, Lang lang)
    Create a memory Graph and read in some data
    static org.apache.jena.rdf.model.Model
    Create a memory Model and read in some data
    static org.apache.jena.rdf.model.Model
    loadModel(String uri, Lang lang)
    Create a memory Model and read in some data
    open(String filenameOrURI)
    Open a stream to the destination (URI or filename) Performs content negotiation, including looking at file extension.
    open(String filenameOrURI, StreamManager streamManager)
    Open a stream to the destination (URI or filename) Performs content negotiation, including looking at file extension.
    static void
    parse(StreamRDF dest, String uri)
    Read RDF data.
    static void
    read(org.apache.jena.graph.Graph graph, InputStream in, String base, Lang lang)
    Read triples into a Model with bytes from an InputStream.
    static void
    read(org.apache.jena.graph.Graph graph, InputStream in, Lang lang)
    Read triples into a Model with bytes from an InputStream.
    static void
    read(org.apache.jena.graph.Graph graph, StringReader in, String base, Lang lang)
    Read triples into a model with chars from a StringReader.
    static void
    read(org.apache.jena.graph.Graph graph, String uri)
    Read triples into a Model from the given location.
    static void
    read(org.apache.jena.graph.Graph graph, String uri, String base, Lang hintLang)
    Read triples into a Model from the given location, with a hint of language.
    static void
    read(org.apache.jena.graph.Graph graph, String uri, Lang hintLang)
    Read triples into a Model from the given location, with a hint of the language (MIME type or short name)
    static void
    read(Dataset dataset, InputStream in, String base, Lang lang)
    Read quads or triples into a dataset with bytes from an input stream.
    static void
    read(Dataset dataset, InputStream in, Lang lang)
    Read quads or triples into a dataset with bytes from an input stream.
    static void
    read(Dataset dataset, StringReader in, String base, Lang lang)
    Read quads into a dataset with chars from a StringReader.
    static void
    read(Dataset dataset, String uri)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    read(Dataset dataset, String uri, String base, Lang hintLang)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    read(Dataset dataset, String uri, Lang hintLang)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    read(org.apache.jena.rdf.model.Model model, InputStream in, String base, Lang lang)
    Read triples into a Model with bytes from an InputStream.
    static void
    read(org.apache.jena.rdf.model.Model model, InputStream in, Lang lang)
    Read triples into a Model with bytes from an InputStream.
    static void
    read(org.apache.jena.rdf.model.Model model, StringReader in, String base, Lang lang)
    Read triples into a model with chars from a StringReader.
    static void
    read(org.apache.jena.rdf.model.Model model, String uri)
    Read triples into a Model from the given location.
    static void
    read(org.apache.jena.rdf.model.Model model, String uri, String base, Lang hintLang)
    Read triples into a Model from the given location, with a hint of language.
    static void
    read(org.apache.jena.rdf.model.Model model, String uri, Lang hintLang)
    Read triples into a Model from the given location, with a hint of the language (MIME type)
    static void
    read(DatasetGraph dataset, InputStream in, String base, Lang lang)
    Read quads or triples into a dataset with bytes from an input stream.
    static void
    read(DatasetGraph dataset, InputStream in, Lang lang)
    Read quads or triples into a dataset with bytes from an input stream.
    static void
    read(DatasetGraph dataset, StringReader in, String base, Lang lang)
    Read quads into a dataset with chars from a StringReader.
    static void
    read(DatasetGraph dataset, String uri)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    read(DatasetGraph dataset, String uri, String base, Lang hintLang)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    read(DatasetGraph dataset, String uri, Lang hintLang)
    Read quads or triples into a Dataset from the given location, with a hint of the language.
    static void
    write(OutputStream out, org.apache.jena.graph.Graph graph, Lang lang)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, org.apache.jena.graph.Graph graph, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, Dataset dataset, Lang lang)
    Write the Dataset to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, Dataset dataset, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, org.apache.jena.rdf.model.Model model, Lang lang)
    Write the model to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, org.apache.jena.rdf.model.Model model, RDFFormat serialization)
    Write the model to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, DatasetGraph dataset, Lang lang)
    Write the DatasetGraph to the output stream in the default serialization for the language.
    static void
    write(OutputStream out, DatasetGraph dataset, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, org.apache.jena.graph.Graph graph, Lang lang)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, org.apache.jena.graph.Graph graph, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, Dataset dataset, Lang lang)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, Dataset dataset, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, org.apache.jena.rdf.model.Model model, Lang lang)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, org.apache.jena.rdf.model.Model model, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, DatasetGraph dataset, Lang lang)
    Write the DatasetGraph to the output stream in the default serialization for the language.
    static void
    write(StringWriter out, DatasetGraph dataset, RDFFormat serialization)
    Write the graph to the output stream in the default serialization for the language.
    static void
    Write an iterator of quads (in N-Quads)
    static void
    writeTriples(OutputStream out, Iterator<org.apache.jena.graph.Triple> iterator)
    Write an iterator of triples (in N-Triples)

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RDFDataMgr

      public RDFDataMgr()
  • Method Details

    • read

      public static void read(org.apache.jena.rdf.model.Model model, String uri)
      Read triples into a Model from the given location. The syntax is determined from input source URI (content negotiation or file extension).
      Parameters:
      model - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      Throws:
      RiotNotFoundException - if the location is not found - the model is unchanged.
    • read

      public static void read(org.apache.jena.graph.Graph graph, String uri)
      Read triples into a Model from the given location. The syntax is determined from input source URI (content negotiation or file extension).
      Parameters:
      graph - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      Throws:
      RiotNotFoundException - if the location is not found - the graph is unchanged.
    • read

      public static void read(org.apache.jena.rdf.model.Model model, String uri, Lang hintLang)
      Read triples into a Model from the given location, with a hint of the language (MIME type)
      Parameters:
      model - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      hintLang - Hint for the syntax.
      Throws:
      RiotNotFoundException - if the location is not found - the model is unchanged.
    • read

      public static void read(org.apache.jena.graph.Graph graph, String uri, Lang hintLang)
      Read triples into a Model from the given location, with a hint of the language (MIME type or short name)
      Parameters:
      graph - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      hintLang - Hint for the syntax.
      Throws:
      RiotNotFoundException - if the location is not found - the graph is unchanged.
    • read

      public static void read(org.apache.jena.rdf.model.Model model, String uri, String base, Lang hintLang)
      Read triples into a Model from the given location, with a hint of language. Throws parse errors depending on the language and reader; the model may be partially updated.
      Parameters:
      model - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      base - Base URI (defaults to uri).
      hintLang - Hint for the syntax
      Throws:
      RiotNotFoundException - if the location is not found - the model is unchanged.
    • read

      public static void read(org.apache.jena.graph.Graph graph, String uri, String base, Lang hintLang)
      Read triples into a Model from the given location, with a hint of language. Throws parse errors depending on the language and reader; the model may be partially updated.
      Parameters:
      graph - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
      base - Base URI (defaults to uri).
      hintLang - Hint for the syntax
      Throws:
      RiotNotFoundException - if the location is not found - the graph is unchanged.
    • read

      public static void read(org.apache.jena.rdf.model.Model model, InputStream in, Lang lang)
      Read triples into a Model with bytes from an InputStream. A base URI and a syntax can be provided. The base URI defaults to "no base" in which case the data should have no relative URIs. The lang gives the syntax of the stream.
      Parameters:
      model - Destination for the RDF read.
      in - InputStream
      lang - Language syntax
    • read

      public static void read(org.apache.jena.graph.Graph graph, InputStream in, Lang lang)
      Read triples into a Model with bytes from an InputStream. A base URI and a syntax can be provided. The base URI defaults to "no base" in which case the data should have no relative URIs. The lang gives the syntax of the stream.
      Parameters:
      graph - Destination for the RDF read.
      in - InputStream
      lang - Language syntax
    • read

      public static void read(org.apache.jena.rdf.model.Model model, InputStream in, String base, Lang lang)
      Read triples into a Model with bytes from an InputStream. A base URI and a syntax can be provided. The base URI defaults to "no base" in which case the data should have no relative URIs. The lang gives the syntax of the stream.
      Parameters:
      model - Destination for the RDF read.
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(org.apache.jena.graph.Graph graph, InputStream in, String base, Lang lang)
      Read triples into a Model with bytes from an InputStream. A base URI and a syntax can be provided. The base URI defaults to "no base" in which case the data should have no relative URIs. The lang gives the syntax of the stream.
      Parameters:
      graph - Destination for the RDF read.
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(org.apache.jena.rdf.model.Model model, StringReader in, String base, Lang lang)
      Read triples into a model with chars from a StringReader.
      Parameters:
      model - Destination for the RDF read.
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(org.apache.jena.graph.Graph graph, StringReader in, String base, Lang lang)
      Read triples into a model with chars from a StringReader.
      Parameters:
      graph - Destination for the RDF read.
      in - InputStream
      base - Base URI
      lang - Language syntax
    • loadModel

      public static org.apache.jena.rdf.model.Model loadModel(String uri)
      Create a memory Model and read in some data
      See Also:
    • loadModel

      public static org.apache.jena.rdf.model.Model loadModel(String uri, Lang lang)
      Create a memory Model and read in some data
      See Also:
    • loadGraph

      public static org.apache.jena.graph.Graph loadGraph(String uri)
      Create a memory Graph and read in some data
      See Also:
    • loadGraph

      public static org.apache.jena.graph.Graph loadGraph(String uri, Lang lang)
      Create a memory Graph and read in some data
      See Also:
    • loadDataset

      public static Dataset loadDataset(String uri)
      Create a memory Dataset and read in some data
      See Also:
    • loadDataset

      public static Dataset loadDataset(String uri, Lang lang)
      Create a memory Dataset and read in some data
      See Also:
    • loadDatasetGraph

      public static DatasetGraph loadDatasetGraph(String uri)
      Create a memory DatasetGraph and read in some data
      See Also:
    • loadDatasetGraph

      public static DatasetGraph loadDatasetGraph(String uri, Lang lang)
      Create a memory DatasetGraph and read in some data
      See Also:
    • read

      public static void read(Dataset dataset, String uri)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
    • read

      public static void read(DatasetGraph dataset, String uri)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
    • read

      public static void read(Dataset dataset, String uri, Lang hintLang)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
      hintLang - Language syntax
    • read

      public static void read(DatasetGraph dataset, String uri, Lang hintLang)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
      hintLang - Language syntax
    • read

      public static void read(Dataset dataset, String uri, String base, Lang hintLang)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
      base - Base URI (defaults to uri).
      hintLang - Language syntax
    • read

      public static void read(DatasetGraph dataset, String uri, String base, Lang hintLang)
      Read quads or triples into a Dataset from the given location, with a hint of the language.
      Parameters:
      dataset - Destination
      uri - URI to read from (includes file: and a plain file name).
      base - Base URI (defaults to uri).
      hintLang - Language syntax
    • read

      public static void read(Dataset dataset, InputStream in, Lang lang)
      Read quads or triples into a dataset with bytes from an input stream.
      Parameters:
      dataset - Destination
      in - InputStream
      lang - Language syntax
    • read

      public static void read(DatasetGraph dataset, InputStream in, Lang lang)
      Read quads or triples into a dataset with bytes from an input stream.
      Parameters:
      dataset - Destination
      in - InputStream
      lang - Language syntax
    • read

      public static void read(Dataset dataset, InputStream in, String base, Lang lang)
      Read quads or triples into a dataset with bytes from an input stream.
      Parameters:
      dataset - Destination
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(DatasetGraph dataset, InputStream in, String base, Lang lang)
      Read quads or triples into a dataset with bytes from an input stream.
      Parameters:
      dataset - Destination
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(Dataset dataset, StringReader in, String base, Lang lang)
      Read quads into a dataset with chars from a StringReader. Use java.io.Readers is not encouraged - use with a StringReader is the primary use case. For files, open a FileInputStream to ensure correct character set handling.
      Parameters:
      dataset - Destination
      in - InputStream
      base - Base URI
      lang - Language syntax
    • read

      public static void read(DatasetGraph dataset, StringReader in, String base, Lang lang)
      Read quads into a dataset with chars from a StringReader. Use java.io.Readers is not encouraged - use with a StringReader is the primary use case. For files, open a FileInputStream to ensure correct character set handling.
      Parameters:
      dataset - Destination
      in - InputStream
      base - Base URI
      lang - Language syntax
    • parse

      public static void parse(StreamRDF dest, String uri)
      Read RDF data. Short for RDFParser.source(uri).parse(dest)
      Parameters:
      dest - Destination for the RDF read.
      uri - URI to read from (includes file: and a plain file name).
    • open

      public static TypedInputStream open(String filenameOrURI)
      Open a stream to the destination (URI or filename) Performs content negotiation, including looking at file extension.
      Parameters:
      filenameOrURI -
      Returns:
      TypedInputStream
    • open

      public static TypedInputStream open(String filenameOrURI, StreamManager streamManager)
      Open a stream to the destination (URI or filename) Performs content negotiation, including looking at file extension.
      Parameters:
      filenameOrURI -
      streamManager -
      Returns:
      TypedInputStream
    • determineLang

      public static Lang determineLang(String target, String ctStr, Lang hintLang)
      Determine the Lang, given the URI target, any content type header string and a hint
    • write

      public static void write(OutputStream out, org.apache.jena.rdf.model.Model model, Lang lang)
      Write the model to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      model - Graph to write
      lang - Language for the serialization.
    • write

      public static void write(OutputStream out, org.apache.jena.rdf.model.Model model, RDFFormat serialization)
      Write the model to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      model - Model to write
      serialization - Serialization format
    • write

      public static void write(StringWriter out, org.apache.jena.rdf.model.Model model, Lang lang)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      model - Model to write
      lang - Serialization format
    • write

      public static void write(StringWriter out, org.apache.jena.rdf.model.Model model, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      model - Model to write
      serialization - Serialization format
    • write

      public static void write(OutputStream out, org.apache.jena.graph.Graph graph, Lang lang)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      graph - Graph to write
      lang - Language for the serialization.
    • write

      public static void write(OutputStream out, org.apache.jena.graph.Graph graph, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      graph - Graph to write
      serialization - Serialization format
    • write

      public static void write(StringWriter out, org.apache.jena.graph.Graph graph, Lang lang)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      graph - Graph to write
      lang - Serialization format
    • write

      public static void write(StringWriter out, org.apache.jena.graph.Graph graph, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      graph - Graph to write
      serialization - Serialization format
    • write

      public static void write(OutputStream out, Dataset dataset, Lang lang)
      Write the Dataset to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      dataset - Dataset to write
      lang - Language for the serialization.
    • write

      public static void write(OutputStream out, Dataset dataset, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      dataset - Dataset to write
      serialization - Serialization format
    • write

      public static void write(StringWriter out, Dataset dataset, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - Writer
      dataset - Dataset to write
      serialization - Serialization format
    • write

      public static void write(StringWriter out, Dataset dataset, Lang lang)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      dataset - Dataset to write
      lang - Language for the serialization.
    • write

      public static void write(OutputStream out, DatasetGraph dataset, Lang lang)
      Write the DatasetGraph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      dataset - DatasetGraph to write
      lang - Language for the serialization.
    • write

      public static void write(OutputStream out, DatasetGraph dataset, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - OutputStream
      dataset - DatasetGraph to write
      serialization - Serialization format
    • write

      public static void write(StringWriter out, DatasetGraph dataset, Lang lang)
      Write the DatasetGraph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      dataset - DatasetGraph to write
      lang - Language for the serialization.
    • write

      public static void write(StringWriter out, DatasetGraph dataset, RDFFormat serialization)
      Write the graph to the output stream in the default serialization for the language.
      Parameters:
      out - StringWriter
      dataset - DatasetGraph to write
      serialization - Serialization format
    • writeTriples

      public static void writeTriples(OutputStream out, Iterator<org.apache.jena.graph.Triple> iterator)
      Write an iterator of triples (in N-Triples)
      Parameters:
      out -
      iterator -
    • writeQuads

      public static void writeQuads(OutputStream out, Iterator<Quad> iterator)
      Write an iterator of quads (in N-Quads)
      Parameters:
      out -
      iterator -
    • createIteratorTriples

      @Deprecated(forRemoval=true) public static Iterator<org.apache.jena.graph.Triple> createIteratorTriples(InputStream input, Lang lang, String baseIRI)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create an iterator over parsing of triples. This function creates a thread unless the Lang is N-Triples.
      Parameters:
      input - Input Stream
      lang - Language
      baseIRI - Base IRI
      Returns:
      Iterator over the triples
    • createIteratorQuads

      @Deprecated(forRemoval=true) public static Iterator<Quad> createIteratorQuads(InputStream input, Lang lang, String baseIRI)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an iterator over parsing of quads. This function creates a thread unless the Lang is N-Quads.
      Parameters:
      input - Input Stream
      lang - Language
      baseIRI - Base IRI
      Returns:
      Iterator over the quads