config.setHostLanguage(Configuration.XQUERY);
final StaticQueryContext staticContext = new StaticQueryContext(config);
staticContext.setBaseURI(new File(queryFile).toURI().toString());
XQueryExpression exp = staticContext.compileQuery(IOUtils.toString(new FileInputStream(queryFile)));
final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
StringWriter res_sw = new StringWriter();
Properties props = new Properties();
//props.setProperty(OutputKeys.METHOD, "text");
props.setProperty(SaxonOutputKeys.WRAP, "no");
props.setProperty(OutputKeys.INDENT, "no");
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
exp.run(dynamicContext, new StreamResult(res_sw), props);
String swresult = sw.toString();
long used = SystemUtils.getHeapUsedMemory();
stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
if(RUN_ONLY) {
res_sw.close();
res_sw = null;
}
System.gc();
used = SystemUtils.getHeapUsedMemory();
stdbuf.append(", used(after GC): " + StringUtils.displayBytesSize(used));
int gcCalled = SystemUtils.countGC() - gcBefore;
stdbuf.append(", total gc count: " + gcCalled);
System.out.println(swresult);
System.out.println(stdbuf.toString());
if(RUN_ONLY) {
return "";//dummy
}
return res_sw.toString();
}