com.holub.database
Class CSVImporter

java.lang.Object
  extended by com.holub.database.CSVImporter
All Implemented Interfaces:
Table.Importer

public class CSVImporter
extends Object
implements Table.Importer

Pass this importer to a Table constructor (such as {link com.holub.database.ConcreteTable#ConcreteTable(Table.Importer)} to initialize a Table from a comma-sparated-value repressentation. For example:

        Reader in = new FileReader( "people.csv" );
        people = new ConcreteTable( new CSVImporter(in) );
        in.close();
        
The input file for a table called "name" with columns "first," "last," and "addrId" would look like this:
        name
        first,  last,   addrId
        Fred,   Flintstone,     1
        Wilma,  Flintstone,     1
        Allen,  Holub,  0
        
The first line is the table name, the second line identifies the columns, and the subsequent lines define the rows.

See Also:
Table, Table.Importer, CSVExporter
©2004 Allen I. Holub. All rights reserved.

This code may be used freely by yourself with the following restrictions:

  1. Your splash screen, about box, or equivalent, must include Allen Holub's name, copyright, and URL. For example:

    This program contains Allen Holub's SQL package.
    (c) 2005 Allen I. Holub. All Rights Reserved.
    http://www.holub.com


    If your program does not run interactively, then the foregoing notice must appear in your documentation.
  2. You may not redistribute (or mirror) the source code.
  3. You must report any bugs that you find to me. Use the form at http://www.holub.com/company/contact.html or send email.
  4. The software is supplied as is. Neither Allen Holub nor Holub Associates are responsible for any bugs (or any problems caused by bugs, including lost productivity or data) in any of this code.

Constructor Summary
CSVImporter(Reader in)
           
 
Method Summary
 void endTable()
           
 Iterator loadColumnNames()
           
 Iterator loadRow()
           
 String loadTableName()
           
 int loadWidth()
           
 void startTable()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVImporter

public CSVImporter(Reader in)
Method Detail

startTable

public void startTable()
                throws IOException
Specified by:
startTable in interface Table.Importer
Throws:
IOException

loadTableName

public String loadTableName()
                     throws IOException
Specified by:
loadTableName in interface Table.Importer
Throws:
IOException

loadWidth

public int loadWidth()
              throws IOException
Specified by:
loadWidth in interface Table.Importer
Throws:
IOException

loadColumnNames

public Iterator loadColumnNames()
                         throws IOException
Specified by:
loadColumnNames in interface Table.Importer
Throws:
IOException

loadRow

public Iterator loadRow()
                 throws IOException
Specified by:
loadRow in interface Table.Importer
Throws:
IOException

endTable

public void endTable()
              throws IOException
Specified by:
endTable in interface Table.Importer
Throws:
IOException