@Override
protected void serializeBinaryBody(final Sequence result, final HttpResponse response) throws RestXqServiceException {
final Iterator<TypedValue> itResult = result.iterator();
while(itResult.hasNext()) {
final TypedValue typedValue = itResult.next();
if(typedValue.getType() == Type.BASE64_BINARY || typedValue.getType() == Type.HEX_BINARY) {
final BinaryValue binaryValue = (BinaryValue)typedValue.getValue();
OutputStream os = null;
try {
os = response.getOutputStream();
binaryValue.streamBinaryTo(os);
} catch(final IOException ioe) {
throw new RestXqServiceException("Error while serializing binary: " + ioe.toString(), ioe);
} finally {
if(os != null) {
try {
os.close();
} catch (final IOException ioe) {
LOG.warn(ioe);
}
}
}
return; //TODO support more than one binary result -- multipart?
} else {
throw new RestXqServiceException("Expected binary value, but found: " + typedValue.getType().name());
}
}
}