You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Attilio Donà <at...@gmail.com> on 2010/05/04 08:57:47 UTC
Camel-csv 2.2.0: reading a single line csv file
Hi all,
I've to read a csv file and I want use camel to do this. Camel bindy seems
to me that doesn't know the csv convention that a field separator can be a
character field using double quotes:
"contains, comma", "another field"
So the adopted solution is camel-csv.
Using camel-csv to parse the csv file as in the camel manual works only if
the csv file has more than one line of data:
// Some comments here
public void doHandleCsvData(List> csvData)
{
// do magic here as in the manual if the file as more than one row of
data
}
If the csv file has 1 row the parameter passed to the method bean
doHandleCsvData is a List.
As a quick workaround, instead of using parametrized generics, it is
possible to do something like this:
public void modelsCsvFile(Exchange exchange) {
List csvData = (List) exchange.getIn().getBody();
if (csvData.get(0).getClass().equals(String.class)) {
log.debug("single row file");
Vendor vendor = vendorDAO.bind((String)csvData.get(0));
Model model = new Model(vendor, (String)csvData.get(1));
modelDAO.bind(model);
return;
}
for (List row : (List)csvData) {
log.debug("read [{}] [{}]", row.get(0), row.get(1));
Vendor vendor = vendorDAO.bind((String)row.get(0));
Model model = new Model(vendor, (String)row.get(1));
modelDAO.bind(model);
}
Attilio
--
View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by Attilio Donà <at...@gmail.com>.
Excuse me, I reply only for correcting the first message format.
Attilio
Attilio Donà wrote:
>
> Hi all,
>
> I've to read a csv file and I want use camel to do this. Camel bindy seems
> to me that doesn't know the csv convention that a field separator can be a
> character field using double quotes:
>
> "contains, comma", "another field"
>
> So the adopted solution is camel-csv.
>
> Using camel-csv to parse the csv file as in the camel manual works only if
> the csv file has more than one line of data:
>
> // Some comments here
> public void doHandleCsvData(List<List<String>> csvData)
> {
> // do magic here as in the manual if the file as more than one row of
> data
> }
>
> If the csv file has 1 row the parameter passed to the method bean
> doHandleCsvData is a List<String>.
>
> As a quick workaround, instead of using parametrized generics, it is
> possible to do something like this:
>
>
> public void modelsCsvFile(Exchange exchange) {
> List csvData = (List) exchange.getIn().getBody();
>
> if (csvData.get(0).getClass().equals(String.class)) {
> log.debug("single row file");
>
> Vendor vendor = vendorDAO.bind((String)csvData.get(0));
> Model model = new Model(vendor, (String)csvData.get(1));
> modelDAO.bind(model);
> return;
> }
>
> for (List row : (List<List>)csvData) {
> log.debug("read [{}] [{}]", row.get(0), row.get(1));
>
> Vendor vendor = vendorDAO.bind((String)row.get(0));
> Model model = new Model(vendor, (String)row.get(1));
> modelDAO.bind(model);
>
> }
>
> Attilio
>
>
--
View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443808.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Charles
Great have you also tested when the field is empty? eg its just "".
On Tue, Jun 15, 2010 at 11:06 AM, cmoulliard <cm...@gmail.com> wrote:
>
> I have committed a modification in camel bindy to be able to work with ",".
> that means that we use as separator the double quotes --> '","'
>
> See test class
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyDoubleQuotesCsvUnmarshallTest.java
>
> to have an example
>
> KR,
>
> Charles
>
> Claus Ibsen-2 wrote:
>>
>> On Tue, May 4, 2010 at 5:19 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> On Tue, May 4, 2010 at 8:57 AM, Attilio Donà <at...@gmail.com>
>>> wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I've to read a csv file and I want use camel to do this. Camel bindy
>>>> seems
>>>> to me that doesn't know the csv convention that a field separator can be
>>>> a
>>>> character field using double quotes:
>>>>
>>>> "contains, comma", "another field"
>>>>
>>>
>>> Yeah that would be good to be able to do with camel-bindy. Do you mind
>>> creating a JIRA ticket?
>>>
>>
>> I have created the JIRA ticket
>> https://issues.apache.org/activemq/browse/CAMEL-2691
>>
>>
>>>
>>>> So the adopted solution is camel-csv.
>>>>
>>>> Using camel-csv to parse the csv file as in the camel manual works only
>>>> if
>>>> the csv file has more than one line of data:
>>>>
>>>> // Some comments here
>>>> public void doHandleCsvData(List> csvData)
>>>> {
>>>> // do magic here as in the manual if the file as more than one row of
>>>> data
>>>> }
>>>>
>>>> If the csv file has 1 row the parameter passed to the method bean
>>>> doHandleCsvData is a List.
>>>>
>>>> As a quick workaround, instead of using parametrized generics, it is
>>>> possible to do something like this:
>>>>
>>>>
>>>> public void modelsCsvFile(Exchange exchange) {
>>>> List csvData = (List) exchange.getIn().getBody();
>>>>
>>>> if (csvData.get(0).getClass().equals(String.class)) {
>>>> log.debug("single row file");
>>>>
>>>> Vendor vendor =
>>>> vendorDAO.bind((String)csvData.get(0));
>>>> Model model = new Model(vendor,
>>>> (String)csvData.get(1));
>>>> modelDAO.bind(model);
>>>> return;
>>>> }
>>>>
>>>> for (List row : (List)csvData) {
>>>> log.debug("read [{}] [{}]", row.get(0),
>>>> row.get(1));
>>>>
>>>> Vendor vendor =
>>>> vendorDAO.bind((String)row.get(0));
>>>> Model model = new Model(vendor,
>>>> (String)row.get(1));
>>>> modelDAO.bind(model);
>>>>
>>>> }
>>>>
>>>> Attilio
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>
> -----
> Charles Moulliard
> SOA Architect
>
> My Blog : http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/
> --
> View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28888858.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by cmoulliard <cm...@gmail.com>.
I have committed a modification in camel bindy to be able to work with ",".
that means that we use as separator the double quotes --> '","'
See test class
https://svn.apache.org/repos/asf/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyDoubleQuotesCsvUnmarshallTest.java
to have an example
KR,
Charles
Claus Ibsen-2 wrote:
>
> On Tue, May 4, 2010 at 5:19 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> On Tue, May 4, 2010 at 8:57 AM, Attilio Donà <at...@gmail.com>
>> wrote:
>>>
>>> Hi all,
>>>
>>> I've to read a csv file and I want use camel to do this. Camel bindy
>>> seems
>>> to me that doesn't know the csv convention that a field separator can be
>>> a
>>> character field using double quotes:
>>>
>>> "contains, comma", "another field"
>>>
>>
>> Yeah that would be good to be able to do with camel-bindy. Do you mind
>> creating a JIRA ticket?
>>
>
> I have created the JIRA ticket
> https://issues.apache.org/activemq/browse/CAMEL-2691
>
>
>>
>>> So the adopted solution is camel-csv.
>>>
>>> Using camel-csv to parse the csv file as in the camel manual works only
>>> if
>>> the csv file has more than one line of data:
>>>
>>> // Some comments here
>>> public void doHandleCsvData(List> csvData)
>>> {
>>> // do magic here as in the manual if the file as more than one row of
>>> data
>>> }
>>>
>>> If the csv file has 1 row the parameter passed to the method bean
>>> doHandleCsvData is a List.
>>>
>>> As a quick workaround, instead of using parametrized generics, it is
>>> possible to do something like this:
>>>
>>>
>>> public void modelsCsvFile(Exchange exchange) {
>>> List csvData = (List) exchange.getIn().getBody();
>>>
>>> if (csvData.get(0).getClass().equals(String.class)) {
>>> log.debug("single row file");
>>>
>>> Vendor vendor =
>>> vendorDAO.bind((String)csvData.get(0));
>>> Model model = new Model(vendor,
>>> (String)csvData.get(1));
>>> modelDAO.bind(model);
>>> return;
>>> }
>>>
>>> for (List row : (List)csvData) {
>>> log.debug("read [{}] [{}]", row.get(0),
>>> row.get(1));
>>>
>>> Vendor vendor =
>>> vendorDAO.bind((String)row.get(0));
>>> Model model = new Model(vendor,
>>> (String)row.get(1));
>>> modelDAO.bind(model);
>>>
>>> }
>>>
>>> Attilio
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
-----
Charles Moulliard
SOA Architect
My Blog : http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/
--
View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28888858.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 4, 2010 at 5:19 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> On Tue, May 4, 2010 at 8:57 AM, Attilio Donà <at...@gmail.com> wrote:
>>
>> Hi all,
>>
>> I've to read a csv file and I want use camel to do this. Camel bindy seems
>> to me that doesn't know the csv convention that a field separator can be a
>> character field using double quotes:
>>
>> "contains, comma", "another field"
>>
>
> Yeah that would be good to be able to do with camel-bindy. Do you mind
> creating a JIRA ticket?
>
I have created the JIRA ticket
https://issues.apache.org/activemq/browse/CAMEL-2691
>
>> So the adopted solution is camel-csv.
>>
>> Using camel-csv to parse the csv file as in the camel manual works only if
>> the csv file has more than one line of data:
>>
>> // Some comments here
>> public void doHandleCsvData(List> csvData)
>> {
>> // do magic here as in the manual if the file as more than one row of
>> data
>> }
>>
>> If the csv file has 1 row the parameter passed to the method bean
>> doHandleCsvData is a List.
>>
>> As a quick workaround, instead of using parametrized generics, it is
>> possible to do something like this:
>>
>>
>> public void modelsCsvFile(Exchange exchange) {
>> List csvData = (List) exchange.getIn().getBody();
>>
>> if (csvData.get(0).getClass().equals(String.class)) {
>> log.debug("single row file");
>>
>> Vendor vendor = vendorDAO.bind((String)csvData.get(0));
>> Model model = new Model(vendor, (String)csvData.get(1));
>> modelDAO.bind(model);
>> return;
>> }
>>
>> for (List row : (List)csvData) {
>> log.debug("read [{}] [{}]", row.get(0), row.get(1));
>>
>> Vendor vendor = vendorDAO.bind((String)row.get(0));
>> Model model = new Model(vendor, (String)row.get(1));
>> modelDAO.bind(model);
>>
>> }
>>
>> Attilio
>>
>> --
>> View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by cmoulliard <cm...@gmail.com>.
Do you want also that the CSV generated contain double quotes like
"xxxx","yyyy " ?
KR,
charles
Claus Ibsen-2 wrote:
>
> Hi
>
> On Tue, May 4, 2010 at 8:57 AM, Attilio Donà <at...@gmail.com>
> wrote:
>>
>> Hi all,
>>
>> I've to read a csv file and I want use camel to do this. Camel bindy
>> seems
>> to me that doesn't know the csv convention that a field separator can be
>> a
>> character field using double quotes:
>>
>> "contains, comma", "another field"
>>
>
> Yeah that would be good to be able to do with camel-bindy. Do you mind
> creating a JIRA ticket?
>
>
>> So the adopted solution is camel-csv.
>>
>> Using camel-csv to parse the csv file as in the camel manual works only
>> if
>> the csv file has more than one line of data:
>>
>> // Some comments here
>> public void doHandleCsvData(List> csvData)
>> {
>> // do magic here as in the manual if the file as more than one row of
>> data
>> }
>>
>> If the csv file has 1 row the parameter passed to the method bean
>> doHandleCsvData is a List.
>>
>> As a quick workaround, instead of using parametrized generics, it is
>> possible to do something like this:
>>
>>
>> public void modelsCsvFile(Exchange exchange) {
>> List csvData = (List) exchange.getIn().getBody();
>>
>> if (csvData.get(0).getClass().equals(String.class)) {
>> log.debug("single row file");
>>
>> Vendor vendor =
>> vendorDAO.bind((String)csvData.get(0));
>> Model model = new Model(vendor,
>> (String)csvData.get(1));
>> modelDAO.bind(model);
>> return;
>> }
>>
>> for (List row : (List)csvData) {
>> log.debug("read [{}] [{}]", row.get(0),
>> row.get(1));
>>
>> Vendor vendor =
>> vendorDAO.bind((String)row.get(0));
>> Model model = new Model(vendor,
>> (String)row.get(1));
>> modelDAO.bind(model);
>>
>> }
>>
>> Attilio
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
-----
Charles Moulliard
SOA Architect
My Blog : http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/
--
View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28856669.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel-csv 2.2.0: reading a single line csv file
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
On Tue, May 4, 2010 at 8:57 AM, Attilio Donà <at...@gmail.com> wrote:
>
> Hi all,
>
> I've to read a csv file and I want use camel to do this. Camel bindy seems
> to me that doesn't know the csv convention that a field separator can be a
> character field using double quotes:
>
> "contains, comma", "another field"
>
Yeah that would be good to be able to do with camel-bindy. Do you mind
creating a JIRA ticket?
> So the adopted solution is camel-csv.
>
> Using camel-csv to parse the csv file as in the camel manual works only if
> the csv file has more than one line of data:
>
> // Some comments here
> public void doHandleCsvData(List> csvData)
> {
> // do magic here as in the manual if the file as more than one row of
> data
> }
>
> If the csv file has 1 row the parameter passed to the method bean
> doHandleCsvData is a List.
>
> As a quick workaround, instead of using parametrized generics, it is
> possible to do something like this:
>
>
> public void modelsCsvFile(Exchange exchange) {
> List csvData = (List) exchange.getIn().getBody();
>
> if (csvData.get(0).getClass().equals(String.class)) {
> log.debug("single row file");
>
> Vendor vendor = vendorDAO.bind((String)csvData.get(0));
> Model model = new Model(vendor, (String)csvData.get(1));
> modelDAO.bind(model);
> return;
> }
>
> for (List row : (List)csvData) {
> log.debug("read [{}] [{}]", row.get(0), row.get(1));
>
> Vendor vendor = vendorDAO.bind((String)row.get(0));
> Model model = new Model(vendor, (String)row.get(1));
> modelDAO.bind(model);
>
> }
>
> Attilio
>
> --
> View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-tp28443740p28443740.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus