@Override public void setSparql(TextWriteHandle sparql) { this.sparql = HandleAccessor.contentAsString(sparql); }
@Override public ServerEvaluationCall xquery(TextWriteHandle xquery) { setContext(Context.ADHOC_XQUERY); code = HandleAccessor.contentAsString(xquery); return this; }
@Override public ServerEvaluationCall javascript(TextWriteHandle javascript) { setContext(Context.ADHOC_JAVASCRIPT); code = HandleAccessor.contentAsString(javascript); return this; }
public String serialize() { if (getHandle() == null) return ""; return HandleAccessor.contentAsString(getHandle()); }
public String serialize() { if (getHandle() == null) return ""; return HandleAccessor.contentAsString(getHandle()); }
String structure = ""; if ( structuredQuery != null ) structure = structuredQuery.serialize(); if ( rawQuery != null ) structure = HandleAccessor.contentAsString(rawQuery.getHandle()); out.write(structure.getBytes("UTF-8")); out.flush(); ((OutputStreamSender) value).write(out); } else { out.write(HandleAccessor.contentAsString(options).getBytes("UTF-8"));
"query with " + optionsBase.getFormat() + "-format options"); String json = HandleAccessor.contentAsString(qdef.options); JsonNode optionsNode = mapper.readTree(json); searchNode.replace("options", optionsNode.get("options")); String json = HandleAccessor.contentAsString(qdef.rawQuery.getHandle()); JsonNode rawQueryNode = mapper.readTree(json); JsonNode queryNode = rawQueryNode.get("query");
type = getJsonType(jsonNode); } else if ( valueObject instanceof AbstractWriteHandle ) { value = HandleAccessor.contentAsString((AbstractWriteHandle) valueObject); HandleImplementation valueBase = HandleAccessor.as((AbstractWriteHandle) valueObject); Format format = valueBase.getFormat();
@Test public void testContentAsString() throws URISyntaxException, IOException { // I'm purposely using a string with a non-ascii character to test // charset issues String hola = "¡Hola!"; System.out.println("Default Java Charset: " + Charset.defaultCharset()); assertEquals("String content mismatch", hola, HandleAccessor.contentAsString(new StringHandle(hola))); assertEquals("byte[] content mismatch", hola, HandleAccessor.contentAsString(new BytesHandle(hola.getBytes("UTF-8")))); URL filePath = this.getClass().getClassLoader().getResource("hola.txt"); assertEquals("Reader content mismatch", hola, HandleAccessor.contentAsString(new ReaderHandle(new StringReader(hola)))); assertEquals("File content mismatch", hola, HandleAccessor.contentAsString(new FileHandle(new File(filePath.toURI())))); assertEquals("InputStream content mismatch", hola, HandleAccessor.contentAsString(new InputStreamHandle(filePath.openStream()))); InputStream fileInputStream = new FileInputStream(new File(filePath.toURI())) { @Override public void close() throws IOException { super.close(); HandleAccessorTest.fileInputStreamWasClosed = true; } }; assertEquals("InputStream content mismatch", hola, HandleAccessor.contentAsString(new InputStreamHandle(fileInputStream))); assertTrue(this.fileInputStreamWasClosed); } }
private CombinedQueryDefinitionImpl parseCombinedQuery(RawCombinedQueryDefinition qdef) { DOMHandle handle = new DOMHandle(); HandleAccessor.receiveContent(handle, HandleAccessor.contentAsString(qdef.getHandle())); Document combinedQueryXml = handle.get(); DOMImplementationLS domImplementation = (DOMImplementationLS) combinedQueryXml.getImplementation();
@Test public void getNullTests() throws DatatypeConfigurationException, JsonProcessingException, IOException { String javascript = "var myNull; myNull"; ServerEvaluationCall call = Common.evalClient.newServerEval().javascript(javascript) .addVariable("myNull", (String) null); try (EvalResultIterator results = call.eval()) { assertEquals("myNull looks wrong", null, results.next().getString()); } try (EvalResultIterator results = call.eval()) { assertEquals("myNull looks wrong", null, results.next().get(new StringHandle()).get()); } try (EvalResultIterator results = call.eval()) { assertEquals("myNull looks wrong", null, results.next().get(new BytesHandle()).get()); } try (EvalResultIterator results = call.eval()) { NullNode jsonNullNode = new ObjectMapper().createObjectNode().nullNode(); assertEquals("myNull looks wrong", jsonNullNode, results.next().get(new JacksonHandle()).get()); } try (EvalResultIterator results = call.eval()) { ReaderHandle valueReader = results.next().get(new ReaderHandle()); String value = HandleAccessor.contentAsString(valueReader); assertEquals("myNull looks wrong", "null", value); } }