com.holub.database
Class CSVExporter

java.lang.Object
  extended by com.holub.database.CSVExporter
All Implemented Interfaces:
Table.Exporter

public class CSVExporter
extends Object
implements Table.Exporter

Pass this exporter to a Table.export(com.holub.database.Table.Exporter) implementation to create a comma-sparated-value version of a Table. For example:

        Table people  = TableFactory.create( ... );
        //...
        Writer out = new FileWriter( "people.csv" );
        people.export( new CSVExporter(out) );
        out.close();
        
The output 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.Exporter, CSVImporter
©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
CSVExporter(Writer out)
           
 
Method Summary
 void endTable()
           
 void startTable()
           
 void storeMetadata(String tableName, int width, int height, Iterator columnNames)
           
 void storeRow(Iterator data)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVExporter

public CSVExporter(Writer out)
Method Detail

storeMetadata

public void storeMetadata(String tableName,
                          int width,
                          int height,
                          Iterator columnNames)
                   throws IOException
Specified by:
storeMetadata in interface Table.Exporter
Throws:
IOException

storeRow

public void storeRow(Iterator data)
              throws IOException
Specified by:
storeRow in interface Table.Exporter
Throws:
IOException

startTable

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

endTable

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