Package com.inrupt.client.rdf4j

package com.inrupt.client.rdf4j

RDF4J RDF support for the Inrupt Java Client Libraries.

The RDF4J module gives two possibilities to read RDF data: through the Service RDF4JService and through the BodyHandler RDF4JBodyHandlers.

A user of the RDF4JService should ensure that this implementation is available on the classpath by adding the following dependency:


Example of using the RDF4J Service toDataset() method to read triples from a trig file into a Dataset:

    RdfService service = ServiceProvider.getRdfService();
    Dataset dataset;
    try (InputStream input = Test.class.getResourceAsStream("/tripleExamples.trig")) {
        dataset = service.toDataset(Syntax.TRIG, input);
    System.out.println("Number of triples in file: " + dataset.size());

Example of using the RDF4J BodyHandler ofModel() method to read the triples from the same trig file into a Model:

    Request request = Request.newBuilder()

    Response<Model> response = client.send(request, RDF4JBodyHandlers.ofModel()).toCompletableFuture().join();

    System.out.println("HTTP status code: " + response.statusCode());
    System.out.println("Number of triples in file: " + response.body().size());

The RDF4JBodyPublishers can be used to write triples. An example that uses the POST method to write a Model:

    ModelBuilder builder = new ModelBuilder();
                .add("https://example.example/predicate", "object");
    Model model =;

    Request request = Request.newBuilder()
            .header("Content-Type", "text/turtle")

    Response<Void> response = client.send(request, Response.BodyHandlers.discarding()).toCompletableFuture().join();

    System.out.println("HTTP status code: " + response.statusCode());