use of org.exist.util.serializer.EXISerializer in project exist by eXist-db.
the class EncodeExiFunction method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (args[0].isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
EXISerializer exiSerializer;
if (args.length > 1) {
if (!args[1].isEmpty()) {
Item xsdItem = args[1].itemAt(0);
try (InputStream xsdInputStream = EXIUtils.getInputStream(xsdItem, context)) {
exiSerializer = new EXISerializer(baos, xsdInputStream);
}
} else {
exiSerializer = new EXISerializer(baos);
}
} else {
exiSerializer = new EXISerializer(baos);
}
Item inputNode = args[0].itemAt(0);
exiSerializer.startDocument();
inputNode.toSAX(context.getBroker(), exiSerializer, new Properties());
exiSerializer.endDocument();
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), baos.toInputStream());
} catch (IOException ioex) {
// TODO - test!
throw new XPathException(this, ErrorCodes.FODC0002, ioex.getMessage());
} catch (EXIException | SAXException exie) {
throw new XPathException(this, new JavaErrorCode(exie.getCause()), exie.getMessage());
}
}
Aggregations