Refine search
/** * Reset logging (log4j). */ public static void resetLogging(String config) { Properties p = new Properties() ; InputStream in = new ByteArrayInputStream(StrUtils.asUTF8bytes(config)) ; try { p.load(in) ; } catch (IOException ex) {} PropertyConfigurator.configure(p) ; System.setProperty("log4j.configuration", "set") ; }
/** ByteBuffer to String */ public static String byteBufferToString(ByteBuffer bb) { byte[] b = new byte[bb.remaining()] ; bb.get(b) ; return StrUtils.fromUTF8bytes(b) ; }
public static String decode(String string) { return StrUtils.decodeHex(string, '%') ; }
@Test public void testCreateIteratorTriples_02() { String x = StrUtils.strjoinNL( "<rdf:RDF", " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"", " xmlns:j.0=\"http://example/\">" , " <rdf:Description rdf:about=\"http://example/s\">" , " <j.0:p rdf:resource=\"http://example/o\"/>" , " </rdf:Description>" , "</rdf:RDF>") ; Iterator<Triple> it = RDFDataMgr.createIteratorTriples(new ByteArrayInputStream(x.getBytes()), RDFLanguages.RDFXML, "http://example/"); assertTrue(it.hasNext()); Triple t = it.next(); assertNotNull(t); assertEquals("http://example/s", t.getSubject().getURI()); assertEquals("http://example/p", t.getPredicate().getURI()); assertEquals("http://example/o", t.getObject().getURI()); assertFalse(it.hasNext()); } }
return ; ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ; String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
private static void preserve_bnodes(Lang sparqlresultlang, Context cxt, boolean same) { ResultSetRewindable rs1 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs1$)))) ; ByteArrayOutputStream x = new ByteArrayOutputStream(); ResultsWriter.create().context(cxt).lang(sparqlresultlang).write(x, rs1); ByteArrayInputStream y = new ByteArrayInputStream(x.toByteArray()); ResultSetRewindable rs2 = ResultSetFactory.copyResults( ResultsReader.create().context(cxt).lang(sparqlresultlang).read(y) ); rs1.reset(); rs2.reset(); if ( same ) assertTrue(ResultSetCompare.equalsExact(rs1, rs2)); else assertFalse(ResultSetCompare.equalsExact(rs1, rs2)); }
private /*public*/ static String encode(Node node, PrefixMapping pmap) { if ( node.isBlank() ) // Raw label. return "_:"+node.getBlankNodeLabel() ; if ( node.isURI() ) { // Pesky spaces //throw new TDBException("Space found in URI: "+node) ; String x = StrUtils.encodeHex(node.getURI(), '_', invalidIRIChars) ; if ( x != node.getURI() ) node = NodeFactory.createURI(x) ; } return NodeFmtLib.str(node) ; }
String datatype = "" ; if ( node.isLiteral() ) lang = node.getLiteralLanguage() ; datatype = node.getLiteralDatatypeURI() ; if ( datatype == null ) datatype = "" ; String sqlStmt = strjoinNL( "INSERT INTO "+TableDescNodes.name()+"(hash,lex,lang,datatype,type) VALUES", " ("+hash+", ",
@Test public void uniontxn_update() { String x = StrUtils.strjoinNL("BASE <http://example/>", "CLEAR ALL ; ", "INSERT DATA { GRAPH <urn:g> { <s> <p> 1}} ; ", "INSERT { GRAPH <urn:g99> { ?s ?p 99} } WHERE { ?s ?p 1 }" ) ; Dataset ds = TDBFactory.createDataset() ; ds.getContext().setTrue(TDB.symUnionDefaultGraph) ; ds.begin(WRITE) ; UpdateRequest req = UpdateFactory.create(x) ; UpdateAction.execute(req, ds) ; ds.commit() ; ds.end() ; ds.begin(READ) ; assertEquals(1, ds.getNamedModel("urn:g99").size()) ; assertEquals(1, ds.getNamedModel("urn:g").size()) ; assertEquals(2, ds.getNamedModel(Quad.unionGraph.getURI()).size()) ; ds.end() ; }
@Test public void combine_extend_04() { String opString = StrUtils.strjoinNL ("(extend ((?x 2))" ," (extend ((?y 3))" ," (distinct" ," (extend ((?a 'A') (?b 'B'))" ," (extend ((?c 'C'))" ," (table unit)" ," )))))" ); String opExpectedString = StrUtils.strjoinNL ("(extend ((?y 3) (?x 2))" ," (distinct" ," (extend ((?c 'C') (?a 'A') (?b 'B'))" ," (table unit))))"); Op op = SSE.parseOp(opString) ; check(op, new TransformExtendCombine(), opExpectedString); }
@Test public void filter_unstable_01() { // Assigned variable used only once can substitute expression for the // later usage of the variable // EXCEPT if the expression is unstable in which case we leave it alone //@formatter:off testNoChange(StrUtils.strjoinNL("(project (?y)", " (filter (exprlist ?x)", " (extend (?x (rand))", " (table unit))))")); //@formatter:on }
@Test public void sparql_update_unionGraph() { // JENA-344 Dataset ds = TDBFactory.createDataset() ; ds.asDatasetGraph().add(SSE.parseQuad("(<g> <s> <p> 123)")) ; ds.getContext().setTrue(TDB.symUnionDefaultGraph) ; String us = StrUtils.strjoinNL( "INSERT { GRAPH <http://example/g2> { ?s ?p 'NEW' } }", "WHERE { ", "?s ?p 123", " }" ) ; UpdateRequest req = UpdateFactory.create(us) ; UpdateAction.execute(req, ds) ; Model m = ds.getNamedModel("http://example/g2") ; assertEquals("Did not find 1 statement in named graph", 1, m.size()) ; }
protected static Table parseTableInt(String... strings) { String x = StrUtils.strjoinNL(strings) ; return SSE.parseTable(x) ; }
private void test (String... strings) { String str = StrUtils.strjoinNL(strings) ; Graph g = SSE.parseGraph(str) ; test(g); }
/** String to ByteBuffer as UTF-8 bytes */ public static ByteBuffer stringToByteBuffer(String str) { byte[] b = StrUtils.asUTF8bytes(str) ; return ByteBuffer.wrap(b) ; }
private void isotest(String[] rs1$2, String[] rs2$2) { ResultSetRewindable rs1 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs1$)))) ; ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs2$)))) ; assertTrue(ResultSetCompare.isomorphic(rs1, rs2)) ; rs1.reset() ; rs2.reset() ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; assertTrue(ResultSetCompare.equalsByValue(rs1, rs2)) ; }
/** Encode using the rules for a component (e.g. ':' and '/' get encoded) * Does not encode non-ASCII characters */ public static String encodeUriComponent(String string) { String encStr = StrUtils.encodeHex(string,'%', charsComponent) ; return encStr ; }
private /*public*/ static Node decode(String s, PrefixMapping pmap) { if ( s.startsWith("_:") ) { s = s.substring(2) ; return NodeFactory.createBlankNode(s) ; } if ( s.startsWith("<") ) { s = s.substring(1,s.length()-1) ; s = StrUtils.decodeHex(s, MarkerChar) ; return NodeFactory.createURI(s) ; } try { // SSE invocation is expensive (??). // Try TokenizerText? // Use for literals only. Node n = SSE.parseNode(s, pmap) ; return n ; } catch (SSEParseException ex) { Log.error(NodeLib.class, "decode: Failed to parse: "+s) ; throw ex ; } }