use of org.beanio.BeanReader in project camel by apache.
the class BeanIOSplitter method evaluate.
public Object evaluate(Exchange exchange) throws Exception {
Message msg = exchange.getIn();
Object body = msg.getBody();
if (factory == null) {
factory = createStreamFactory(exchange.getContext());
}
BeanReader beanReader = null;
if (body instanceof WrappedFile) {
body = ((WrappedFile) body).getFile();
}
if (body instanceof File) {
File file = (File) body;
beanReader = factory.createReader(getStreamName(), file);
}
if (beanReader == null) {
Reader reader = msg.getMandatoryBody(Reader.class);
beanReader = factory.createReader(getStreamName(), reader);
}
BeanIOIterator iterator = new BeanIOIterator(beanReader);
BeanReaderErrorHandler errorHandler = getOrCreateBeanReaderErrorHandler(configuration, exchange, null, iterator);
beanReader.setErrorHandler(errorHandler);
return iterator;
}
use of org.beanio.BeanReader in project camel by apache.
the class BeanIODataFormat method readModels.
private List<Object> readModels(Exchange exchange, InputStream stream) throws Exception {
List<Object> results = new ArrayList<Object>();
BufferedReader streamReader = IOHelper.buffered(new InputStreamReader(stream, getEncoding()));
BeanReader in = factory.createReader(getStreamName(), streamReader);
BeanReaderErrorHandler errorHandler = getOrCreateBeanReaderErrorHandler(configuration, exchange, results, null);
in.setErrorHandler(errorHandler);
try {
Object readObject;
while ((readObject = in.read()) != null) {
if (readObject instanceof BeanIOHeader) {
exchange.getOut().getHeaders().putAll(((BeanIOHeader) readObject).getHeaders());
}
results.add(readObject);
}
} finally {
in.close();
}
return results;
}
Aggregations