@Override public TypedInputStream open(String resourceName) { if ( classLoader == null ) return null ; InputStream in = classLoader.getResourceAsStream(resourceName) ; if ( in == null ) { if ( StreamManager.logAllLookups && log.isTraceEnabled() ) log.trace("Failed to open: "+resourceName) ; return null ; } if ( StreamManager.logAllLookups && log.isTraceEnabled() ) log.trace("Found: "+resourceName) ; ContentType ct = RDFLanguages.guessContentType(resourceName) ; // No sensible base URI. return new TypedInputStream(in, ct, null) ; }
@Override public TypedInputStream open(String resourceName) { if ( classLoader == null ) return null ; InputStream in = classLoader.getResourceAsStream(resourceName) ; if ( in == null ) { if ( StreamManager.logAllLookups && log.isTraceEnabled() ) log.trace("Failed to open: "+resourceName) ; return null ; } if ( StreamManager.logAllLookups && log.isTraceEnabled() ) log.trace("Found: "+resourceName) ; ContentType ct = RDFLanguages.guessContentType(resourceName) ; // No sensible base URI. return new TypedInputStream(in, ct, null) ; }
log.trace("Found: "+filenameOrURI) ; ContentType ct = RDFLanguages.guessContentType(filenameOrURI) ; return new TypedInputStream(in, ct, filenameOrURI) ;
log.trace("Found: "+filenameOrURI) ; ContentType ct = RDFLanguages.guessContentType(filenameOrURI) ; return new TypedInputStream(in, ct, filenameOrURI) ;
@Override public TypedInputStream performOpen(String uri) { if ( uri.startsWith("ftp://") ) { try { URL url = new URL(uri) ; InputStream in = url.openStream() ; ContentType ct = RDFLanguages.guessContentType(uri) ; return new TypedInputStream(in, ct) ; } catch (MalformedURLException ex) { throw new RiotException("Bad FTP URL: "+uri, ex) ; } catch (IOException ex) { // This includes variations on "not found" IO.exception(ex) ; } } return null ; }
@Override public TypedInputStream performOpen(String uri) { if ( uri.startsWith("ftp://") ) { try { URL url = new URL(uri) ; InputStream in = url.openStream() ; ContentType ct = RDFLanguages.guessContentType(uri) ; return new TypedInputStream(in, ct) ; } catch (MalformedURLException ex) { throw new RiotException("Bad FTP URL: "+uri, ex) ; } catch (IOException ex) { // This includes variations on "not found" IO.exception(ex) ; } } return null ; }
log.trace("Found: "+filenameIRI+thisDirLogStr) ; ContentType ct = RDFLanguages.guessContentType(filenameIRI) ; return new TypedInputStream(in, ct, filenameIRI) ; } catch (IOException ioEx)
log.trace("Found: "+filenameIRI+thisDirLogStr) ; ContentType ct = RDFLanguages.guessContentType(filenameIRI) ; return new TypedInputStream(in, ct, filenameIRI) ; } catch (IOException ioEx)
/** Determine the content type to be used, given the target URL, the content-type from * Content Negotiation and a hint language. This is a pragmatic balance. * A content-type of "text/plain" is ignored - it is too often wrong. */ /*package*/ static ContentType determineCT(String target, String ctStr, Lang hintLang) { boolean isTextPlain = WebContent.contentTypeTextPlain.equals(ctStr) ; if ( ctStr != null ) ctStr = WebContent.contentTypeCanonical(ctStr) ; // The decision is: // Content type (but not text/plain) > hint > file extension. // If it's text plain, we ignore it because a lot of naive // server setups return text/plain for any file type. // (It was never registered as being N-triples; // that was only for RDF 2004 testing.) ContentType ct = null ; if ( ! isTextPlain ) // Not guaranteed to be registered as a language here. ct = (ctStr==null) ? null : ContentType.create(ctStr) ; if ( ct == null && hintLang != null ) ct = hintLang.getContentType() ; if ( ct == null ) ct = RDFLanguages.guessContentType(target) ; return ct ; }
ct = RDFLanguages.guessContentType(target) ;
/** Write the source to the file. * <p> * If neither {@code Lang} nor {@code RDFFormat} are set, an attempt to * guess an RDF Syntax is made from the file extension. * <p>Output to "-" goes to stdout. * @param filename */ public void output(String filename) { Objects.requireNonNull(filename, "Null filename"); RDFFormat fmt = format; if ( fmt == null ) { ContentType ct = RDFLanguages.guessContentType(filename); if ( ct == null ) throw new RiotException("Lang and RDFformat unset and can't determine syntax from '"+filename+"'"); Lang lang = RDFLanguages.contentTypeToLang(ct); if ( lang == null ) throw new RiotException("No syntax registered for '"+ct.getContentType()+"'"); fmt = RDFWriterRegistry.defaultSerialization(lang); } if ( filename.equals("-") ) { output(System.out, fmt); return; } Path p = Paths.get(filename); try ( OutputStream out1 = Files.newOutputStream(p); OutputStream out = new BufferedOutputStream(out1, BUF_SIZE)){ output(out, fmt); } catch (IOException ex) { IO.exception(ex); } }
try { InputStream in = Files.newInputStream(path); ContentType ct = RDFLanguages.guessContentType(urlStr) ; return new TypedInputStream(in, ct);