public static ResultSetCloseable fromXml(InputStream xmlInputStream) { ResultSet rs = ResultSetFactory.fromXML(xmlInputStream); ResultSetCloseable result = new ResultSetCloseable(rs, xmlInputStream); return result; } }
public static ResultSet parseResultSet(final String resultURI) throws IOException { if (resultURI.endsWith("srx")) return ResultSetFactory.fromXML(URI.create(resultURI).toURL().openStream()); else if (resultURI.endsWith("ttl")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_TTL); else if (resultURI.endsWith("rdf")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_XML); else throw new OpenError("Unknown format."); }
public static ResultSet parseResultSet(final String resultURI) throws IOException { if (resultURI.endsWith("srx")) return ResultSetFactory.fromXML(URI.create(resultURI).toURL().openStream()); else if (resultURI.endsWith("ttl")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_TTL); else if (resultURI.endsWith("rdf")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_XML); else throw new OpenError("Unknown format."); }
public static ResultSet parseResultSet(final String resultURI) throws IOException { if (resultURI.endsWith("srx")) return ResultSetFactory.fromXML(URI.create(resultURI).toURL().openStream()); else if (resultURI.endsWith("ttl")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_TTL); else if (resultURI.endsWith("rdf")) return ResultSetFactory.load(resultURI, ResultsFormat.FMT_RDF_XML); else throw new OpenError("Unknown format."); }
public ResultSet _asResultSet() throws SQLException { final InputStream in = cacheEntry.getInputStream(); ResultSet resultSet = ResultSetFactory.fromXML(in); ResultSetCloseable result = new ResultSetCloseable(resultSet, in); return result; }
public void sparqlSelectQuery(String queryStr, ResultSetConsumer consumer) throws RDFServiceException { //QueryEngineHTTP qh = new QueryEngineHTTP(readEndpointURI, queryStr); try { HttpGet meth = new HttpGet(new URIBuilder(readEndpointURI).addParameter("query", queryStr).build()); meth.addHeader("Accept", "application/sparql-results+xml"); HttpContext context = getContext(meth); HttpResponse response = context != null ? httpClient.execute(meth, context) : httpClient.execute(meth); try { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode > 399) { log.error("response " + statusCode + " to query. \n"); log.debug("update string: \n" + queryStr); throw new RDFServiceException("Unable to perform SPARQL UPDATE"); } try (InputStream in = response.getEntity().getContent()) { consumer.processResultSet(ResultSetFactory.fromXML(in)); } } finally { EntityUtils.consume(response.getEntity()); } } catch (IOException | URISyntaxException ioe) { throw new RuntimeException(ioe); } }
ResultSet resultSet = ResultSetFactory.fromXML(in); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); switch (resultFormat) {
@Test public void resultset_02() { ResultSet rs = make($rs) ; ByteArrayOutputStream out = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsXML(out, rs) ; ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromXML(in) ; areIsomorphic(rs, rs2); }
@Override public ResultSetRewindable readFrom(Class<ResultSetRewindable> type, Type type1, Annotation[] antns, javax.ws.rs.core.MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream in) throws IOException { if (log.isTraceEnabled()) log.trace("Reading ResultSet with HTTP headers: {} MediaType: {}", httpHeaders, mediaType); // result set needs to be rewindable because results might be processed multiple times, e.g. to calculate hash and write response // TO-DO: construct Jena's ResultFormat and then pass to ResultSet.load(in, format) if (mediaType.isCompatible(com.atomgraph.core.MediaType.APPLICATION_SPARQL_RESULTS_XML_TYPE)) return ResultSetFactory.makeRewindable(ResultSetFactory.fromXML(in)); if (mediaType.isCompatible(com.atomgraph.core.MediaType.APPLICATION_SPARQL_RESULTS_JSON_TYPE)) return ResultSetFactory.makeRewindable(ResultSetFactory.fromJSON(in)); if (mediaType.isCompatible(com.atomgraph.core.MediaType.APPLICATION_SPARQL_RESULTS_CSV_TYPE)) return ResultSetFactory.makeRewindable(CSVInput.fromCSV(in)); if (mediaType.isCompatible(com.atomgraph.core.MediaType.APPLICATION_SPARQL_RESULTS_CSV_TYPE)) return ResultSetFactory.makeRewindable(TSVInput.fromTSV(in)); throw new IllegalStateException("ResultSet MediaType should be readable but no Jena reader matched"); }
@Test public void test_RS_1() { ResultSetRewindable rs1 = new ResultSetMem() ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsXML(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromXML(ins) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
public static void main(String[] args) { String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "PREFIX mo: <http://purl.org/ontology/mo/> "; String sparqlQueryString = p1+ "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; System.out.println("SparqlQuery: "); System.out.println(sparqlQueryString); System.out.println("wget -S -O test.txt "+"'http://dbtune.org:2105/sparql/?query="+sparqlQueryString+"'"); ResultSet rs = ResultSetFactory.fromXML(xml); @SuppressWarnings("unchecked") List<QuerySolution> l = ResultSetFormatter.toList(rs); for (QuerySolution binding : l) { System.out.println(binding.toString()); } System.out.println("Executing query"); rs = null; //String service = "http://dbtune.org:2105/sparql/"; //QueryEngineHTTP queryExecution = new QueryEngineHTTP(service, sparqlQueryString); try{ SparqlQuery s = new SparqlQuery(sparqlQueryString, new SparqlEndpoint(new URL("http://dbtune.org:2105/sparql/"))); s.send(); //rs = queryExecution.execSelect(); //ByteArrayOutputStream baos = new ByteArrayOutputStream(); //ResultSetFormatter.outputAsJSON(baos, rs); //System.out.println( baos.toString("UTF-8")); } catch (Exception e) { // should never happen as UTF-8 is supported e.printStackTrace(); } }
@Test public void test_RS_2() { ResultSetRewindable rs1 = makeRewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsXML(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromXML(ins) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_1_str() { ResultSetRewindable rs1 = new ResultSetMem() ; String x = ResultSetFormatter.asXMLString(rs1) ; rs1.reset() ; InputStream in = new ByteArrayInputStream(StrUtils.asUTF8bytes(x)); ResultSet rs2 = ResultSetFactory.fromXML(in) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
ResultSet rs = ResultSetFactory.fromXML(in); QueryIterator qIter = QueryIter.materialize(new QueryIteratorResultSet(rs));
@Test public void test_RS_2_str() { ResultSetRewindable rs1 = makeRewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; String x = ResultSetFormatter.asXMLString(rs1) ; rs1.reset() ; InputStream in = new ByteArrayInputStream(StrUtils.asUTF8bytes(x)); ResultSet rs2 = ResultSetFactory.fromXML(in) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }