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); }
@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); }
@Override public void handle(String baseIRI, HttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); String ct = (entity.getContentType()==null) ? null : entity.getContentType().getValue() ; stream = new TypedInputStream(entity.getContent(), ct); }
/** Read RDF data. * @param sink Destination for the RDF read. * @param in Bytes to read. * @param base Base URI (defaults to uri). * @param hintLang Hint for the syntax * @param context Content object to control reading process. */ public static void parse(StreamRDF sink, InputStream in, String base, Lang hintLang, Context context) { process(sink, new TypedInputStream(in), base, hintLang, context) ; }
@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) ; }
public void importRdf(InputStream rdf) { final Stopwatch stopwatch = Stopwatch.createStarted(); final StreamRDF rdfStreamReader = new RdfStreamReader(); RDFDataMgr.parse(rdfStreamReader, new TypedInputStream(rdf)); LOG.info("Import took {}", stopwatch.stop()); }
public void importRdf(InputStream rdf, String mimetype) { final Stopwatch stopwatch = Stopwatch.createStarted(); final StreamRDF rdfStreamReader = new RdfStreamReader(); RDFDataMgr.parse(rdfStreamReader, new TypedInputStream(rdf, mimetype)); LOG.info("Import took {}", stopwatch.stop()); }
@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) ; }
return new TypedInputStream(in, ct, filenameOrURI) ;
return new TypedInputStream(in, ct, filenameOrURI) ;
/** Read quads or triples into a dataset with bytes from an input stream. * @param dataset Destination * @param in InputStream * @param base Base URI * @param lang Language syntax */ public static void read(DatasetGraph dataset, InputStream in, String base, Lang lang) { StreamRDF dest = StreamRDFLib.dataset(dataset) ; process(dest, new TypedInputStream(in), base, lang, null) ; }
/** Read triples into a Model with bytes from an InputStream. * A base URI and a syntax can be provided. * The base URI defualts to "no base" in which case the data should have no relative URIs. * The lang gives the syntax of the stream. * @param graph Destination for the RDF read. * @param in InputStream * @param base Base URI * @param lang Language syntax */ public static void read(Graph graph, InputStream in, String base, Lang lang) { StreamRDF dest = StreamRDFLib.graph(graph) ; process(dest, new TypedInputStream(in), base, lang, 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 ; }
@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 ; }
return new TypedInputStream(in, ct, filenameIRI) ; } catch (IOException ioEx)
return new TypedInputStream(in, ct, filenameIRI) ; } catch (IOException ioEx)
public void parseFile(String filename) { TypedInputStream in = null ; if ( filename.equals("-") ) { in = new TypedInputStream(System.in) ; parseFile("http://base/", "stdin", in) ; } else { try { in = RDFDataMgr.open(filename) ; } catch (Exception ex) { System.err.println("Can't open '"+filename+"' "+ex.getMessage()) ; return ; } parseFile(null, filename, in) ; IO.close(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) ; }
InputStream in = Files.newInputStream(path); ContentType ct = RDFLanguages.guessContentType(urlStr) ; return new TypedInputStream(in, ct);