TableView/Parsing csv

From: Gilbert Rebhan (mailforgilbert_at_gmx.de)
Date: 04/25/04


Date: Sun, 25 Apr 2004 10:31:38 +0200

Hi,

i've written a plugin for eclipse that provides a tableview,
reading a csvfile.

til now the csvfile had always the format =

String|String
String|String
... with 2 Strings on every line, no blanks

but now the writing of the csvfiles has changed, so
lines like =

String|blank
or
blank|String
... may appear

Now my sorting get's cluttered :(

My ViewContentProvider has the following method =

--------------------------
class ViewContentProvider implements IStructuredContentProvider
{
protected Vector csvdata;
public final static int NB_COLUMNS = 2;
public void initVectors(String csvfile)
{
     String aLine;
     csvdata = new Vector();
     Vector row = new Vector();
     try
     {
     if (csvfile != null)
     {
         FileInputStream fin = new
         FileInputStream(csvfile);
         BufferedReader br = new BufferedReader(new
         InputStreamReader(fin));
         // extract csvdata
     while ((aLine = br.readLine()) != null)
     {
     StringTokenizer st = new StringTokenizer(aLine, "|");
         while (st.hasMoreTokens())
         {
         row.add(st.nextToken());
             if (row.size() == NB_COLUMNS)
             {
             csvdata.add(row);
             row = new Vector();
             }
         }
     }
             if (!row.isEmpty())
             csvdata.add(row);
             br.close();
     }
         } catch (Exception e)
             {
             e.printStackTrace();
             }
---------------------------

Question =

i want to skip those lines containing only one field,
simply ignore them, how to filter them out ?

I use jdk 1.3.1_03, so no regexp

Thanks for any hints!!

bye4now, Gilbert