public boolean process(Exchange exchange, AsyncCallback callback) {
ObjectHelper.notNull(dataFormat, "dataFormat");
// if stream caching is enabled then use that so we can stream accordingly
// for example to overflow to disk for big streams
CachedOutputStream cos;
ByteArrayOutputStream os;
if (exchange.getContext().getStreamCachingStrategy().isEnabled()) {
cos = new CachedOutputStream(exchange);
os = null;
} else {
cos = null;
os = new ByteArrayOutputStream();
}
Message in = exchange.getIn();
Object body = in.getBody();
// lets setup the out message before we invoke the dataFormat
// so that it can mutate it if necessary
Message out = exchange.getOut();
out.copyFrom(in);
try {
if (cos != null) {
dataFormat.marshal(exchange, body, cos);
out.setBody(cos.newStreamCache());
} else {
dataFormat.marshal(exchange, body, os);
byte[] data = os.toByteArray();
out.setBody(data);
}