Search in sources :

Example 1 with StringSerializer

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());
}
Also used : Str(org.brackit.xquery.atomic.Str) PrintStream(java.io.PrintStream) QueryException(org.brackit.xquery.QueryException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Sequence(org.brackit.xquery.xdm.Sequence) File(java.io.File) StringSerializer(org.brackit.xquery.util.serialize.StringSerializer)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 QueryException (org.brackit.xquery.QueryException)1 Str (org.brackit.xquery.atomic.Str)1 StringSerializer (org.brackit.xquery.util.serialize.StringSerializer)1 Sequence (org.brackit.xquery.xdm.Sequence)1