/** Read a result set from a URL or filename. */ public ResultSet read(String urlOrFilename) { Objects.nonNull(urlOrFilename); try ( TypedInputStream in = StreamManager.get(context).open(urlOrFilename) ) { Lang lang = determinLang(in, urlOrFilename); return readResultSet(in.getInputStream(), lang); } }
/** Read a result set or boolean from a URL or filename. */ public SPARQLResult readAny(String urlOrFilename) { Objects.nonNull(urlOrFilename); try ( TypedInputStream in = StreamManager.get(context).open(urlOrFilename) ) { Lang lang = determinLang(in, urlOrFilename); return readAny(in.getInputStream(), lang); } }
private void writeJsonLd(final OutputStream output, final DatasetGraph graph, final IRI... profiles) { final String profile = getCustomJsonLdProfile(profiles); final RDFFormat format = canUseCustomJsonLdProfile(profile) ? JSONLD_COMPACT_FLAT : getJsonLdProfile(profiles); final WriterDatasetRIOT writer = RDFDataMgr.createDatasetWriter(format); final PrefixMap pm = RiotLib.prefixMap(graph); final String base = null; final JsonLDWriteContext ctx = new JsonLDWriteContext(); if (canUseCustomJsonLdProfile(profile)) { LOGGER.debug("Setting JSON-LD context with profile: {}", profile); final String c = cache.get(profile, p -> { try (final TypedInputStream res = HttpOp.execHttpGet(profile)) { return IOUtils.toString(res.getInputStream(), UTF_8); } catch (final IOException | HttpException ex) { LOGGER.warn("Error fetching profile {}: {}", p, ex.getMessage()); return null; } }); if (nonNull(c)) { ctx.setJsonLDContext(c); ctx.setJsonLDContextSubstitution("\"" + profile + "\""); } } writer.write(output, graph, pm, base, ctx); }
private void writeJsonLd(final OutputStream output, final DatasetGraph graph, final IRI... profiles) { final String profile = getCustomJsonLdProfile(profiles); final RDFFormat format = canUseCustomJsonLdProfile(profile) ? JSONLD_COMPACT_FLAT : getJsonLdProfile(profiles); final WriterDatasetRIOT writer = RDFDataMgr.createDatasetWriter(format); final PrefixMap pm = RiotLib.prefixMap(graph); final String base = null; final JsonLDWriteContext ctx = new JsonLDWriteContext(); if (canUseCustomJsonLdProfile(profile)) { LOGGER.debug("Setting JSON-LD context with profile: {}", profile); final String c = cache.get(profile, p -> { try (final TypedInputStream res = HttpOp.execHttpGet(profile)) { return IOUtils.toString(res.getInputStream(), UTF_8); } catch (final IOException | HttpException ex) { LOGGER.warn("Error fetching profile {}: {}", p, ex.getMessage()); return null; } }); if (nonNull(c)) { ctx.setJsonLDContext(c); ctx.setJsonLDContextSubstitution("\"" + profile + "\""); } } writer.write(output, graph, pm, base, ctx); }
throw new UpdateException("Attempt to load quads into a graph"); RDFParser parser = RDFParser .source(input.getInputStream()) .forceLang(lang) .build();
.context(context) .build() .readAny(in.getInputStream());