camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: fix CAMEL-7450: CsvDataFormat unable to setup header when useMaps=true
Date Mon, 26 May 2014 12:34:41 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x 1dc303183 -> 093192f8f


fix CAMEL-7450: CsvDataFormat unable to setup header when useMaps=true


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e3a2c59a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e3a2c59a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e3a2c59a

Branch: refs/heads/camel-2.13.x
Commit: e3a2c59af53c0bd0653be71aadedb093f42c791f
Parents: 1dc3031
Author: carlo <ccancellieri@hotmail.com>
Authored: Tue May 20 18:30:32 2014 +0200
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon May 26 20:26:22 2014 +0800

----------------------------------------------------------------------
 .../camel/dataformat/csv/CsvDataFormat.java     | 21 ++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e3a2c59a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
index 309ae0e..c2e1541 100644
--- a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
+++ b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
@@ -131,16 +131,25 @@ public class CsvDataFormat implements DataFormat {
         try {
             reader = IOHelper.buffered(new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange)));
             CSVParser parser = new CSVParser(reader, strategy);
-
+            if (skipFirstLine) {
+                // read one line ahead and skip it
+                parser.getLine();
+            }
             CsvLineConverter<?> lineConverter;
             if (useMaps) {
-                lineConverter = CsvLineConverters.getMapLineConverter(parser.getLine());
+            	final CSVField[] fields=this.config.getFields();
+            	final String[] fieldS;
+            	if (fields!=null){
+            		fieldS=new String[fields.length];
+	            	for (int i=0; i<fields.length; i++){
+	            		fieldS[i]=fields[i].getName();
+	            	}
+            	} else {
+            		fieldS=parser.getLine();
+            	}
+            	lineConverter = CsvLineConverters.getMapLineConverter(fieldS);
             } else {
                 lineConverter = CsvLineConverters.getListConverter();
-                if (skipFirstLine) {
-                    // read one line ahead and skip it
-                    parser.getLine();
-                }
             }
 
             @SuppressWarnings({"unchecked", "rawtypes"}) CsvIterator<?> csvIterator
= new CsvIterator(parser, reader, lineConverter);


Mime
View raw message