Search in sources :

Example 1 with DataSet

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataSet(net.sf.flatpack.DataSet) DataSetList(org.apache.camel.component.flatpack.DataSetList) Parser(net.sf.flatpack.Parser)

Example 2 with DataSet

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());
    }
}
Also used : DataSet(net.sf.flatpack.DataSet) Parser(net.sf.flatpack.Parser)

Example 3 with DataSet

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());
}
Also used : DataSet(net.sf.flatpack.DataSet) Test(org.junit.Test)

Aggregations

DataSet (net.sf.flatpack.DataSet)3 Parser (net.sf.flatpack.Parser)2 InputStreamReader (java.io.InputStreamReader)1 DataSetList (org.apache.camel.component.flatpack.DataSetList)1 Test (org.junit.Test)1