Menu

#21 Retrieval of previously read line number and line string

2.0.0-beta-1
closed
None
6
2012-09-16
2011-11-14
Pat
No

I'd like to see two features, which should be easily added to SuperCSV:
A possibility to retrieve the line number and the line itself as a string of the previously read line.

Discussion

  • James Bassett

    James Bassett - 2011-11-14

    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?

     
  • Pat

    Pat - 2011-11-14

    Hi James,

    1. getLineNumber():
      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.

     
  • James Bassett

    James Bassett - 2011-11-14

    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

     
  • Pat

    Pat - 2011-11-14

    When you say, "cannot be processed from a business point of view" what do
    you mean?
    Imagine that an application processes a csv file containing primary keys of some database table. If a record cannot be found in the database this is considered as a business error.
    In this case, the untouched, original line should be printed to another file
    But this is currently not possible with SuperCSV.

     
  • Kasper B. Graversen

    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.

     
  • James Bassett

    James Bassett - 2012-07-06

    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).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.