Retrieval of previously read line number and line string
A fast, programmer-friendly, free CSV library for Java
Brought to you by:
jamesbassett,
kbg
HI Pat,
AbstractCsvReader (http://supercsv.sourceforge.net/javadoc/org/supercsv/io/AbstractCsvReader.html) provides two methods that might help:
getLineNumber() - gets the current position in the file
get(int N) - Gets column N of the current line
That's assuming you want this information when reading and not from inside a CellProcessor?
Hi James,
I am not quite sure at the moment, but I think there some problem with getLineNumber(). For now, you can forgot about this part of my request
2.get(int N)
I really need the unproccessed, complete line, including delimiters. E.g. think of that you want to output all lines which cannot be processed from a business point of view.
Hi Pat,
I'll have a look into this to see if it's possible with the current API. If it is, it would probably involve surrounding each 'read' with a try/catch and extracting the line number and row details.
When you say, "cannot be processed from a business point of view" what do you mean?
1. There was a problem parsing the CSV or a constraint (CellProcessor) failed
2. The line was successfully read, but the business logic (where the data was used) failed and you just want to keep track of that
James
Hi thanks for the report..
I think the idea about getting the raw input is a valid one and a good idea!.
I dont like the idea of caching the previous line, I think this is something you should be able to do with the current API yourself.
I've implemented both of these features for the upcoming release (see revision 228).
All readers and writers now have getLineNumber(), which returns the actual line number being read/written (i.e. in the physical CSV file), and getRowNumber(), which returns the current row being read/written (essentially the number of records so far, including the header). Both line number and row number start at 1.
Also, readers now have a getUntokenizedRow() method, which returns the raw untokenized line previously read (please note that any line separators within multiline quoted cells will be converted to \n, and there will be no trailing line separator).