Search in sources :

Example 1 with RDFFormat

use of org.apache.jena.riot.RDFFormat in project jena by apache.

the class TestMultipleEmbedded method graphToHttpEntity.

/** Create an HttpEntity for the graph */
protected static HttpEntity graphToHttpEntity(final Graph graph) {
    final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS;
    ContentProducer producer = new ContentProducer() {

        @Override
        public void writeTo(OutputStream out) {
            RDFDataMgr.write(out, graph, syntax);
        }
    };
    EntityTemplate entity = new EntityTemplate(producer);
    ContentType ct = syntax.getLang().getContentType();
    entity.setContentType(ct.getContentType());
    return entity;
}
Also used : ContentType(org.apache.jena.atlas.web.ContentType) OutputStream(java.io.OutputStream) EntityTemplate(org.apache.http.entity.EntityTemplate) RDFFormat(org.apache.jena.riot.RDFFormat) ContentProducer(org.apache.http.entity.ContentProducer)

Example 2 with RDFFormat

use of org.apache.jena.riot.RDFFormat in project jena by apache.

the class TestEmbeddedFuseki method graphToHttpEntity.

/** Create an HttpEntity for the graph */
protected static HttpEntity graphToHttpEntity(final Graph graph) {
    final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS;
    ContentProducer producer = new ContentProducer() {

        @Override
        public void writeTo(OutputStream out) {
            RDFDataMgr.write(out, graph, syntax);
        }
    };
    EntityTemplate entity = new EntityTemplate(producer);
    ContentType ct = syntax.getLang().getContentType();
    entity.setContentType(ct.getContentType());
    return entity;
}
Also used : ContentType(org.apache.jena.atlas.web.ContentType) OutputStream(java.io.OutputStream) EntityTemplate(org.apache.http.entity.EntityTemplate) RDFFormat(org.apache.jena.riot.RDFFormat) ContentProducer(org.apache.http.entity.ContentProducer)

Example 3 with RDFFormat

use of org.apache.jena.riot.RDFFormat in project jena by apache.

the class DatasetGraphAccessorHTTP method graphToHttpEntity.

/** Create an HttpEntity for the graph */
protected HttpEntity graphToHttpEntity(final Graph graph) {
    final RDFFormat syntax = getOutboundSyntax();
    ContentProducer producer = new ContentProducer() {

        @Override
        public void writeTo(OutputStream out) {
            RDFDataMgr.write(out, graph, syntax);
        }
    };
    EntityTemplate entity = new EntityTemplate(producer);
    String ct = syntax.getLang().getContentType().getContentType();
    entity.setContentType(ct);
    return entity;
}
Also used : OutputStream(java.io.OutputStream) EntityTemplate(org.apache.http.entity.EntityTemplate) RDFFormat(org.apache.jena.riot.RDFFormat) ContentProducer(org.apache.http.entity.ContentProducer)

Example 4 with RDFFormat

use of org.apache.jena.riot.RDFFormat in project jena by apache.

the class tdbdump method exec.

@Override
protected void exec() {
    DatasetGraph dsg = super.getDatasetGraphTDB();
    // Prefer stream over fully pretty output formats.
    RDFFormat fmt = modLangOutput.getOutputStreamFormat();
    //if ( fmt != null && StreamRDFWriter.registered(fmt) )
    if (fmt == null)
        fmt = modLangOutput.getOutputFormatted();
    if (fmt == null)
        // Default.
        fmt = RDFFormat.NQUADS;
    if (!RDFLanguages.isQuads(fmt.getLang()))
        throw new CmdException("Databases can be dumped only in quad formats (e.g. Trig, N-Quads), not " + fmt.getLang());
    RDFDataMgr.write(System.out, dsg, fmt);
}
Also used : CmdException(jena.cmd.CmdException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) RDFFormat(org.apache.jena.riot.RDFFormat)

Example 5 with RDFFormat

use of org.apache.jena.riot.RDFFormat in project jena by apache.

the class TestJsonLDWriter method roundTrip.

/**
     * Write a model and parse it back: you should get the same thing
     * (except with frame)
     */
@Test
public final void roundTrip() {
    String ns = "http://www.a.com/foo/";
    Model m = simpleModel(ns);
    m.setNsPrefix("ex", ns);
    for (RDFFormat f : JSON_LD_FORMATS) {
        if (((RDFFormat.JSONLDVariant) f.getVariant()).isFrame())
            continue;
        String s = toString(m, f, null);
        Model m2 = parse(s);
        assertTrue(m2.isIsomorphicWith(m));
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) JsonString(org.apache.jena.atlas.json.JsonString) RDFFormat(org.apache.jena.riot.RDFFormat) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

RDFFormat (org.apache.jena.riot.RDFFormat)6 OutputStream (java.io.OutputStream)3 ContentProducer (org.apache.http.entity.ContentProducer)3 EntityTemplate (org.apache.http.entity.EntityTemplate)3 ContentType (org.apache.jena.atlas.web.ContentType)2 HashSet (java.util.HashSet)1 CmdException (jena.cmd.CmdException)1 JsonString (org.apache.jena.atlas.json.JsonString)1 BaseTest (org.apache.jena.atlas.junit.BaseTest)1 Model (org.apache.jena.rdf.model.Model)1 Lang (org.apache.jena.riot.Lang)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Test (org.junit.Test)1