use of org.brackit.xquery.util.serialize.StringSerializer in project sirix by sirixdb.
the class Serialize method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final Sequence sequence = args[0];
if (sequence == null) {
return Int32.ZERO;
}
final boolean format = FunUtil.getBoolean(args, 1, "prettyPrint", false, false);
final String file = FunUtil.getString(args, 2, "file", null, null, false);
final PrintStream buf;
if (file == null) {
buf = IOUtils.createBuffer();
} else {
try {
buf = new PrintStream(new FileOutputStream(new File(file)));
} catch (final FileNotFoundException e) {
throw new QueryException(SDBFun.ERR_FILE_NOT_FOUND, e);
}
}
new StringSerializer(buf).setFormat(format).serialize(sequence);
return new Str(buf.toString());
}
Aggregations