Search in sources :

Example 1 with StreamManager

use of org.apache.jena.riot.system.stream.StreamManager in project jena by apache.

the class RDFParserBuilder method build.

/** Build an {@link RDFParser}. The parser takes it's configuration from this builder and can not then be changed.
     * The source must be set.
     * When a parser is used, it is takes the source and sends output to an {@link StreamRDF}.
     * <p>  
     * Shortcuts:
     * <ul>
     * <li>{@link #parse(DatasetGraph)} - parse the source and output to a {@code DatasetGraph}
     * <li>{@link #parse(Graph)} - parse the source and output to a {@code Graph}
     * <li>{@link #parse(StreamRDF)} - parse the source and output to a {@code StreamRDF}
     * </ul>
     * 
     * @return RDFParser
     */
public RDFParser build() {
    // Build what we can now - some things have to be built in the parser.
    if (uri == null && path == null && content == null && inputStream == null && javaReader == null)
        throw new RiotException("No source specified");
    // Setup the HTTP client.
    HttpClient client = buildHttpClient();
    FactoryRDF factory$ = buildFactoryRDF();
    ErrorHandler errorHandler$ = errorHandler;
    if (errorHandler$ == null)
        errorHandler$ = ErrorHandlerFactory.getDefaultErrorHandler();
    if (path != null && baseUri == null)
        baseUri = IRILib.filenameToIRI(path.toString());
    if (path == null && baseUri == null && uri != null)
        baseUri = uri;
    StreamManager sMgr = streamManager;
    if (sMgr == null)
        sMgr = StreamManager.get(context);
    // Can't build the profile here as it is Lang/conneg dependent.
    return new RDFParser(uri, path, content, inputStream, javaReader, sMgr, client, hintLang, forceLang, baseUri, strict, checking, resolveURIs, canonicalLiterals, resolver, factory$, errorHandler$, context);
}
Also used : StreamManager(org.apache.jena.riot.system.stream.StreamManager) HttpClient(org.apache.http.client.HttpClient)

Example 2 with StreamManager

use of org.apache.jena.riot.system.stream.StreamManager in project jena by apache.

the class TestRDFParser method source_streamManager.

@Test
public void source_streamManager() {
    StreamManager sMgr = new StreamManager();
    sMgr.addLocator(new LocatorFile(DIR));
    Graph graph = GraphFactory.createGraphMem();
    RDFParser.create().streamManager(sMgr).source("file:data.rdf").forceLang(Lang.TTL).parse(graph);
    assertEquals(3, graph.size());
}
Also used : Graph(org.apache.jena.graph.Graph) StreamManager(org.apache.jena.riot.system.stream.StreamManager) LocatorFile(org.apache.jena.riot.system.stream.LocatorFile) Test(org.junit.Test)

Example 3 with StreamManager

use of org.apache.jena.riot.system.stream.StreamManager in project jena by apache.

the class TestStreamManager method beforeClass.

@BeforeClass
public static void beforeClass() {
    streamMgrStd = StreamManager.get();
    streamMgrDir = new StreamManager();
    // Not current directory.
    streamMgrDir.addLocator(new LocatorFile(directory));
    streamMgrDir.addLocator(new LocatorHTTP());
    streamMgrHere = new StreamManager();
    // Not current directory.
    streamMgrHere.addLocator(new LocatorFile());
    streamMgrHere.addLocator(new LocatorHTTP());
    streamMgrNull = new StreamManager();
}
Also used : LocatorHTTP(org.apache.jena.riot.system.stream.LocatorHTTP) StreamManager(org.apache.jena.riot.system.stream.StreamManager) LocatorFile(org.apache.jena.riot.system.stream.LocatorFile) BeforeClass(org.junit.BeforeClass)

Aggregations

StreamManager (org.apache.jena.riot.system.stream.StreamManager)3 LocatorFile (org.apache.jena.riot.system.stream.LocatorFile)2 HttpClient (org.apache.http.client.HttpClient)1 Graph (org.apache.jena.graph.Graph)1 LocatorHTTP (org.apache.jena.riot.system.stream.LocatorHTTP)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1