/** @deprecated Use {@link #getContentType} */ @Deprecated public String getMimeType() { return getContentType() ; }
public static TypedInputStream wrap(InputStream in) { //Sometimes this is used to intentional loose the content type (in tests). // if ( in instanceof TypedInputStream ) { // return (TypedInputStream)in; // } return new TypedInputStream(in); }
/** Read RDF data. * @param sink Destination for the RDF read. * @param in Bytes to read. * @param base Base URI * @param context Content object to control reading process. */ public static void parse(StreamRDF sink, TypedInputStream in, String base, Context context) { Lang hintLang = RDFLanguages.contentTypeToLang(in.getMediaType()) ; process(sink, new TypedInputStream(in), base, hintLang, context) ; }
public static org.apache.jena.util.TypedStream convert(TypedInputStream in) { return new org.apache.jena.util.TypedStream(in, in.getContentType(), in.getCharset()); }
String contentType = input.getContentType(); Lang lang = RDFDataMgr.determineLang(source, contentType, Lang.TTL); if ( lang == null ) throw new UpdateException("Attempt to load quads into a graph"); RDFParser parser = RDFParser .source(input.getInputStream()) .forceLang(lang) .build();
@Test public void locatorFile_05() { LocatorFile loc = new LocatorFile() ; TypedInputStream ts = loc.open(testingDir+"data.ttl") ; assertTrue("Not equal: "+WebContent.contentTypeTurtle+" != "+ts.getMediaType(), WebContent.contentTypeTurtle.equalsIgnoreCase(ts.getContentType())) ; }
/** 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 RDF data. * @param sink Destination for the RDF read. * @param in Bytes to read. * @param base Base URI * @param context Content object to control reading process. * @deprecated To be removed. Use {@code RDFParser.source(in).lang(lang).base(base).context(context).parse(sink)} */ @Deprecated public static void parse(StreamRDF sink, TypedInputStream in, String base, Context context) { Objects.requireNonNull(in, "TypedInputStream is null") ; Lang hintLang = RDFLanguages.contentTypeToLang(in.getMediaType()) ; processFromTypedInputStream(sink, in, base, hintLang, context) ; }
@Override public void close() { tis.close(); } }
@Override public ResultSet execSelect() { if(tis != null) { throw new RuntimeException("Query execution already running"); } tis = RDFDataMgr.open(fileNameOrUrl); Lang lang = RDFDataMgr.determineLang(fileNameOrUrl, null, null); String base = tis.getBaseURI(); Iterator<Triple> itTriple = RDFDataMgr.createIteratorTriples(tis, lang, base); Function<Triple, Binding> fn = Functions.compose( F_QuadToBinding.fn, F_TripleToQuad.fn); Iterator<Binding> itBinding = Iterators.transform(itTriple, fn); QueryIter queryIter = new QueryIterPlainWrapper(itBinding); List<String> varNames = Arrays.asList("g", "s", "p", "o"); ResultSet rs = ResultSetFactory.create(queryIter, varNames); return rs; };
ContentType ct = WebContent.determineCT(in.getContentType(), null, url); Lang lang = RDFLanguages.contentTypeToLang(ct); .context(context) .build() .readAny(in.getInputStream());
public static com.hp.hpl.jena.util.TypedStream convert(TypedInputStream in) { return new com.hp.hpl.jena.util.TypedStream(in, in.getContentType(), in.getCharset()) ; }
/** 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); } }
ContentType ct = in.getMediaType() ;
@Override public void close() throws IOException { super.close() ; if ( connectMgr != null ) connectMgr.shutdown() ; }
public static ExtendedIterator<Triple> createTripleIterator(String fileNameOrUrl, Lang langHint) { TypedInputStream tis = RDFDataMgr.open(fileNameOrUrl); Lang lang = RDFDataMgr.determineLang(fileNameOrUrl, null, langHint); String base = tis.getBaseURI(); Iterator<Triple> itTriple = RDFDataMgr.createIteratorTriples(tis, lang, base); ExtendedIterator<Triple> result = ExtendedIteratorClosable.create(itTriple, tis); return result; } }
private InputStream execCommon(TypedInputStream stream) throws QueryExceptionHTTP { // Assume response code must be 200 if we got here responseCode = 200; responseMessage = "OK" ; // Get the returned content type so we can expose this later via the // getContentType() method // We strip any parameters off the returned content type e.g. // ;charset=UTF-8 since code that // consumes our getContentType() method will expect a bare MIME type contentTypeResult = stream.getContentType(); if (contentTypeResult != null && contentTypeResult.contains(";")) { contentTypeResult = contentTypeResult.substring(0, contentTypeResult.indexOf(';')); } // NB - Content Encoding is now handled at a higher level // so we don't have to worry about wrapping the stream at all return stream; }
@Override public void handle(String baseIRI, HttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); if ( entity == null ) { stream = new TypedInputStream(EOFInputStream.empty, (String)null); return; } String ct = (entity.getContentType() == null) ? null : entity.getContentType().getValue(); stream = new TypedInputStream(entity.getContent(), ct); }
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 InputStream execCommon(TypedInputStream stream) throws QueryExceptionHTTP { // Assume response code must be 200 if we got here responseCode = 200; // Get the returned content type so we can expose this later via the // getContentType() method // We strip any parameters off the returned content type e.g. // ;charset=UTF-8 since code that // consumes our getContentType() method will expect a bare MIME type contentTypeResult = stream.getContentType(); if (contentTypeResult != null && contentTypeResult.contains(";")) { contentTypeResult = contentTypeResult.substring(0, contentTypeResult.indexOf(';')); } // NB - Content Encoding is now handled at a higher level // so we don't have to worry about wrapping the stream at all return stream; }