/** @deprecated Use {@link #getContentType} */ @Deprecated public String getMimeType() { return getContentType() ; }
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; }
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; }
public static org.apache.jena.util.TypedStream convert(TypedInputStream in) { return new org.apache.jena.util.TypedStream(in, in.getContentType(), in.getCharset()); }
public static com.hp.hpl.jena.util.TypedStream convert(TypedInputStream in) { return new com.hp.hpl.jena.util.TypedStream(in, in.getContentType(), in.getCharset()) ; }
private static void process(StreamRDF destination, TypedInputStream in, String baseUri, Lang hintLang, Context context) { ContentType ct = determineCT(baseUri, in.getContentType(), hintLang) ; if ( ct == null ) throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : stream="+in.getContentType()+" : hint="+hintLang+")") ; ReaderRIOT reader = getReader(ct) ; if ( reader == null ) throw new RiotException("No parser registered for content type: "+ct.getContentType()) ; reader.read(in, baseUri, ct, destination, context) ; }
private Lang determinLang(TypedInputStream in, String url) { if ( in == null ) throw new RiotNotFoundException(url); Lang lang = forceLang; if ( lang == null ) { ContentType ct = WebContent.determineCT(in.getContentType(), hintLang, url); lang = RDFLanguages.contentTypeToLang(ct); } if ( lang == null ) throw new RiotException("Can't indentify the result set syntax from "+url); return lang; }
/** * Small convenience wrapper for default-loading of an RDF resource, * which would actually fit for RDFDataMgr * * @param resourceName * @return */ public static Stream<Triple> createTripleStream(String resourceName) { TypedInputStream in = RDFDataMgr.open(resourceName); Lang lang = RDFDataMgr.determineLang(resourceName, in.getContentType(), Lang.TURTLE); Iterator<Triple> it = RDFDataMgr.createIteratorTriples(in, lang, "http://example.org/"); return Streams.stream(it); }
@Deprecated private static void processFromTypedInputStream(StreamRDF sink, TypedInputStream in, String baseUri, Lang hintLang, Context context) { // If the input stream comes with a content type, use that in preference to the hint (compatibility). // Except for text/plain. // Do here, which duplicates RDFParser, because "TypedInputStream" gets lost at RDFParser if ( in.getContentType() != null ) { // Special case of text/plain. ContentType ct = WebContent.determineCT(in.getContentType(), hintLang, null); Lang lang2 = RDFLanguages.contentTypeToLang(ct); hintLang = lang2 ; } RDFParser.create() .source(in) .base(baseUri) .lang(hintLang) // We made the decision above. .forceLang(hintLang) .context(context) .parse(sink); } // ---- Support for RDFDataMgr.parse only.
@Override protected Model readModelWorker(Model model, String filenameOrURI, String baseURI, String syntax) { // Doesn't call open() - we want to make the syntax guess // based on the mapped URI. String mappedURI = mapURI(filenameOrURI) ; if ( log.isDebugEnabled() && !mappedURI.equals(filenameOrURI) ) log.debug("Map: " + filenameOrURI + " => " + mappedURI) ; Lang lang = (syntax != null) ? RDFLanguages.nameToLang(syntax) : RDFLanguages.resourceNameToLang(mappedURI, Lang.RDFXML) ; // Not : RDFDataMgr.read(model, mappedURI, baseURI, lang); // Allow model.read to be overridden e.g. by OntModel which does import processing. if ( baseURI == null ) baseURI = SysRIOT.chooseBaseIRI(filenameOrURI) ; try(TypedInputStream in = streamManager.openNoMapOrNull(mappedURI)) { if ( in == null ) { FmtLog.debug(log, "Failed to locate '%s'", mappedURI); throw new NotFoundException("Not found: "+filenameOrURI) ; } Lang lang2 = RDFDataMgr.determineLang(mappedURI, in.getContentType(), lang); // May be overridden by model implementation. model.read(in, baseURI, lang2.getName()) ; } return model ; }
@Override public Dataset fetchDataset() { if ( destination == null ) throw new ARQException("Dataset operations not available - no dataset URL provided"); Dataset ds = DatasetFactory.createTxnMem(); Txn.executeWrite(ds, ()->{ TypedInputStream s = exec(()->HttpOp.execHttpGet(destination, acceptDataset, this.httpClient, this.httpContext)); Lang lang = RDFLanguages.contentTypeToLang(s.getContentType()); RDFDataMgr.read(ds, s, lang); }); return ds; }
@Override public Dataset fetchDataset() { if ( destination == null ) throw new ARQException("Dataset operations not available - no dataset URL provided"); Dataset ds = DatasetFactory.createTxnMem(); Txn.executeWrite(ds, ()->{ TypedInputStream s = exec(()->HttpOp.execHttpGet(destination, acceptDataset, this.httpClient, this.httpContext)); Lang lang = RDFLanguages.contentTypeToLang(s.getContentType()); RDFDataMgr.read(ds, s, lang); }); return ds; }
/** Parse when there is a URI to guide the choice of syntax */ private void parseURI(StreamRDF destination) { // Source by uri or path. try (TypedInputStream input = openTypedInputStream(uri, path)) { ReaderRIOT reader; ContentType ct; if ( forceLang != null ) { @SuppressWarnings("deprecation") ReaderRIOTFactory r = RDFParserRegistry.getFactory(forceLang); if ( r == null ) throw new RiotException("No parser registered for language: " + forceLang); ct = forceLang.getContentType(); reader = createReader(r, forceLang); } else { // No forced language. // Conneg and hint, ignoring text/plain. ct = WebContent.determineCT(input.getContentType(), hintLang, baseUri); if ( ct == null ) throw new RiotException("Failed to determine the content type: (URI=" + baseUri + " : stream=" + input.getContentType()+")"); reader = createReader(ct); if ( reader == null ) throw new RiotException("No parser registered for content type: " + ct.getContentType()); } read(reader, input, null, baseUri, context, ct, destination); } }
@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())) ; }
if ( in == null ) throw new NotFoundException(url) ; String contentType = in.getContentType() ;
Lang lang = RDFDataMgr.determineLang(source, s.getContentType(), null) ;
String contentType = input.getContentType(); Lang lang = RDFDataMgr.determineLang(source, contentType, Lang.TTL); if ( lang == null )
ContentType ct = WebContent.determineCT(in.getContentType(), null, url); Lang lang = RDFLanguages.contentTypeToLang(ct);
RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType())) ; assertTrue(g.isIsomorphicWith(g2)) ;
RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType())) ; assertTrue(g.isIsomorphicWith(g2)) ;