I have a csv file with input content separated with comma ",". I want to convert that into text file with "|" delimiter. I'm using apache camel CsvDataFormat to convert the given csv data format.I can be able to convert the csv content to pipe delimited string. I have two more constants which I have assigned to two variables.I would like to enrich the content of the output data with two additional fields as shown in expected output.
Input
test.csv
Jack Dalton, 115, mad at Averell
Joe Dalton, 105, calming Joe
William Dalton, 105, keeping Joe from killing
Averell Averell Dalton, 80, playing with Rantanplan
Lucky Luke, 120, capturing the Daltons
Test.java
public class Test{
private String name = "Hell0";
private String address = "134 johen rd";
}
ConverterRoute.java
public class ConverterRoute implements RoutesBuilder {
private static final String SOURCE_INPUT_PATH = "file://inbox?fileName=test.csv";
private static final String SOURCE_OUTPUT_PATH = "file://outbox?fileName=file.txt";
public void addRoutesToCamelContext(CamelContext context) throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
try {
CsvDataFormat csvDataFormat = new CsvDataFormat();
csvDataFormat.setDelimiter('|');
csvDataFormat.setHeaderDisabled(true);
from(SOURCE_INPUT_PATH).
unmarshal().csv().
marshal(csvDataFormat).
to(SOURCE_OUTPUT_PATH)
.end();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Output
file.txt
Jack Dalton| 115 | mad at Averell
Joe Dalton| 105 | calming Joe
William Dalton | 105 | keeping Joe from killing
Averell Averell Dalton| 80| playing with Rantanplan
Lucky Luke| 120| capturing the Daltons
Expected Output
file.txt
Jack Dalton| 115 | mad at Averell | Hell0 | 134 johen rd
Joe Dalton| 105 | calming Joe | Hell0 | 134 johen rd
William Dalton | 105 | keeping Joe from killing | Hell0 | 134 johen rd
Averell Averell Dalton| 80| playing with Rantanplan | Hell0 | 134 johen rd
Lucky Luke| 120| capturing the Daltons | Hell0 | 134 johen rd
In the above output file.txt the last two columns are the two constants which I have in my Test.java pojo class. I would like to enrich my pojo fields into the final output. Is there a way I can achieve the result.