@Override public Sequence execute(StaticContext sctx, QueryContext ctx, final Sequence[] args) throws QueryException { if (args[1] == null) { return Int32.ZERO; } try { IntNumeric count = Int32.ZERO; String uri = ((Atomic) args[0]).stringValue(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(URIHandler.getOutputStream(uri, true))); Iter it = args[1].iterate(); try { Item item; while ((item = it.next()) != null) { out.write(item.toString()); count = count.inc(); } } finally { it.close(); } out.close(); return count; } catch (IOException e) { throw new QueryException(e, IOFun.IO_WRITEFILE_INT_ERROR); } }
@Override public void close() { it.close(); }