use of net.sf.flatpack.DataSet in project camel by apache.
the class FlatpackDataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
InputStreamReader reader = new InputStreamReader(stream, IOHelper.getCharsetName(exchange));
try {
Parser parser = createParser(exchange, reader);
DataSet dataSet = parser.parse();
return new DataSetList(dataSet);
} finally {
reader.close();
}
}
use of net.sf.flatpack.DataSet in project camel by apache.
the class FlatpackProducer method process.
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
Parser parser = endpoint.createParser(exchange);
DataSet dataSet = parser.parse();
if (dataSet.getErrorCount() > 0) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("Flatpack has found %s errors while parsing", dataSet.getErrorCount()));
throw new FlatpackException(sb.toString(), exchange, dataSet.getErrors());
}
if (endpoint.isSplitRows()) {
int counter = 0;
while (dataSet.next()) {
endpoint.processDataSet(exchange, dataSet, counter++);
}
} else {
endpoint.processDataSet(exchange, dataSet, dataSet.getRowCount());
}
}
use of net.sf.flatpack.DataSet in project camel by apache.
the class DelimitedErrorWithUnmarshalTest method testCamel.
@Test
public void testCamel() throws Exception {
results.expectedMessageCount(3);
dataset.setExpectedMessageCount(1);
results.assertIsSatisfied();
dataset.assertIsSatisfied();
DataSet ds = dataset.getExchanges().get(0).getIn().getBody(DataSet.class);
assertNotNull(ds);
assertEquals(2, ds.getErrorCount());
assertEquals(3, ds.getRowCount());
}
Aggregations