com.ricebridge.csvman
Class CsvManager

java.lang.Object
  extended bycom.ricebridge.csvman.CsvManager

public class CsvManager
extends Object

This is the main class for loading and saving CSV files.

Quick Start:

To load a CSV file from disk as a List of String[] arrays:

    CsvManager cm      = new CsvManager();
    List       csvData = cm.load( "/path/to/file.csv" );
    for( int line = 0; line < csvData.size(); line++ ) {
      String[] lineData = (String[]) csvData.get( line );
      // do stuff with lineData
    }
  
The best way to learn how to use CSV Manager is to start with the Getting Started guide, which takes you through all the details.

Loading and Saving CSV Data

The CsvManager class provides the following ways to load and save CSV data:

Sources of CSV Data

CSV data can be loaded from the following types of input sources:

All the CSV load methods accept an Object as their first parameter. This object should be one of the data sources listed above. We use an Object so that you only have to learn about a one type of method to load CSV data.

For ease-of-use, a String parameter as the data source is normally considered to be a file path. Use the Text object to load CSV data directly from a String variable in memory.

Destinations for CSV Data

CSV data can be saved to the following types of output destinations (sinks):

All the CSV save methods accept an Object as their first parameter. This object should be one of the data sinks listed above. We use an Object so that you only have to learn about a one type of method to save CSV data.

To save data to a String variable in memory, use an empty Text object as the data sink. You can then call Text.getText() to get the String containing the output CSV.

How to Find the Method You Need

Here are all the methods to load CSV data:

Here are all the methods to save CSV data:

Event-driven Interfaces

If the predefined methods of input and output are not suitable, you can implement your own access to your CSV data. The LineListener interface can be used via the load(Object,LineListener) method to get direct access to the CSV data as it is loaded. Using an implementation of this interface means that you can load CSV data and place it in any data structure that you require.

If you want to provide data to save in a CSV format, you can use a LineProvider instance to provide the data by calling the save(Object,LineProvider) method.

Please note: to use the LineListener interface, you should extend the support class CustomLineListener, as this will provide you with future-compatibility and error-handling support. Similarly, extend CustomLineProvider when creating your own LineProviders.

Streaming Data

To load CSV data from a file as a data stream that you control, use the makeLoader(Object) method. This returns a CsvLoader object that you can use to control the loading of CSV data lines one at a time.

To save CSV data to a file as a data stream that you control, use the makeSaver(Object) method. This returns a CsvSaver object that you can use to control the saving of CSV data lines one at a time.

Options for CSV format

Since there is no standard CSV format, you may encounter a number of variations in the basic layout of a CSV file. Some of the most common variations can be set via the convenience methods in this class, such as setSeparator(java.lang.String) and setQuote(char). For a full description of all the available options, refer to the CsvSpec class. The options used by CsvManager are stored in a CsvSpec object and you can access the current CsvSpec with getCsvSpec(). You can set the current options with setCsvSpec(com.ricebridge.csvman.CsvSpec). There are also a number of shortcut methods for common formats: makeExcelSpec() and makeUnixSpec() for example.

Background Processing

It is possible to perform the loading and saving operations in a background Thread. To do this, set setRunInBackground(boolean) to true. This creates a daemon Thread (which halts automatically if the main Thread halts) where the loading or saving operation is performed. You may call methods such as getLineCount() before processing has finished to monitor the process.

Statistics

The CsvManager provides a number of statistics on the loading and saving process:

For a quick summary of these statistics, use the getStatsSummary() method.

Error Messages and Exception Handling

Normally a CsvManagerException is thrown as soon as an error occurs, and processing halts. If you set setIgnoreBadLines(boolean) to true then errors are collected and processing continues until all data lines are processed. This allows you to load as much valid data as possible. You can get the collected error messages (as BadLine objects) from getBadLines() and the original text of the corresponding bad lines from BadLine.getOriginalLine().

When an error occurs this class throws a CsvManagerException which is a subclass of RuntimeException Since RuntimeExceptions need not be declared none of the methods in this class declare that that they throw any Exceptions. You can choose to catch these CsvManagerExceptions directly or let them pass up to other exception handling within your code. Each CsvManagerException contains an explanation of the error and a set of error values which give more information about the cause of the error. Calling toString on a CsvManagerException will return a user-friendly description of the problem. Calling getMessage on a CsvManagerException will return a technical description of the problem. See CsvManagerException for a more detailed description of how to work with CsvManagerExceptions.

See Also:
CsvManagerException

Constructor Summary
CsvManager()
          Create a new instance of CsvManager.
CsvManager(CsvSpec pCsvSpec)
          Create a new instance of CsvManager using the specified CsvSpec CSV format specification.
 
Method Summary
 double getAverageTimePerLineInSeconds()
          Get the average time taken to process each line in seconds.
 long getBadLineCount()
          Get the number of badly formatted lines of data when loading or saving.
 List getBadLines()
          Get a list of descriptions (BadLine) of any badly formatted data lines encountered.
 CsvManagerStore getCsvManagerStore()
          CsvManagerStore is a utility class for handling LineListener and LineProvider instances.
 CsvSpec getCsvSpec()
          Set the CsvSpec, a specification for CSV file format variation to use.
 Date getEndDate()
          Get the Date at which processing of data lines ended.
 long getLineCount()
          Get the number of lines of data loaded or saved.
 boolean getRunInBackground()
          Get the status of the run in background setting.
 Date getStartDate()
          Get the Date at which processing started.
 String getStatsSummary()
          Get a summary String containing the statistics of the previous or running operation.
 long getTimeTaken()
          Get the total time in milliseconds taken to process all lines.
 double getTimeTakenInSeconds()
          Get the total time in seconds taken to process all lines.
 boolean isFinished()
          Returns true when the loading or saving process is finished.
 List load(File pCsvFile)
          Deprecated.
 void load(File pCsvFile, LineListener pLineListener)
          Deprecated.
 List load(InputStream pInputStream)
          Deprecated.
 void load(InputStream pInputStream, LineListener pLineListener)
          Deprecated.
 List load(Object pSource)
          Load CSV data as a List of String[] arrays.
 void load(Object pSource, LineListener pLineListener)
          Load CSV data using your own LineListener.
 List load(Object pSource, LineSpec pLineSpec)
          Load CSV data as a List of String[] arrays.
 void load(Object pSource, LineSpec pLineSpec, LineListener pLineListener)
          Load CSV data using your own LineListener.
 List load(String pCsvFilePath)
          Deprecated.
 void load(String pCsvFilePath, LineListener pLineListener)
          Deprecated.
 List loadAsLists(File pCsvFile)
          Deprecated.
 List loadAsLists(InputStream pInputStream)
          Deprecated.
 List loadAsLists(Object pSource)
          Load CSV data as a List of Lists of Strings.
 List loadAsLists(Object pSource, LineSpec pLineSpec)
          Load CSV data as a List of Lists of Strings.
 List loadAsLists(String pCsvFilePath)
          Deprecated.
 List loadAsListsFromString(String pCsvData)
          Deprecated.  
 List loadBeans(Object pSource, BeanSpec pBeanSpec)
          Load CSV data into a List of Java Beans.
 List loadBeans(Object pSource, LineSpec pLineSpec, BeanSpec pBeanSpec)
          Load CSV data as a List of Java Beans.
 List loadFromString(String pCsvData)
          Deprecated.  
 void loadFromString(String pCsvData, LineListener pLineListener)
          Deprecated.  
 ResultSet loadResultSet(File pCsvFile, boolean pHasHeaders)
          Deprecated.  
 ResultSet loadResultSet(InputStream pInputStream, boolean pHasHeaders)
          Deprecated.  
 ResultSet loadResultSet(Object pSource)
          Load CSV data as a ResultSet.
 ResultSet loadResultSet(Object pSource, LineSpec pLineSpec)
          Load CSV data as a ResultSet.
 ResultSet loadResultSet(String pCsvFilePath, boolean pHasHeaders)
          Deprecated.  
 ResultSet loadResultSetFromString(String pCsvData, boolean pHasHeaders)
          Deprecated.  
 TableModel loadTableModel(File pCsvFile, boolean pHasHeaders)
          Deprecated.  
 TableModel loadTableModel(InputStream pInputStream, boolean pHasHeaders)
          Deprecated.  
 TableModel loadTableModel(Object pSource)
          Load CSV data as a TableModel.
 TableModel loadTableModel(Object pSource, LineSpec pLineSpec)
          Load CSV data as a TableModel.
 TableModel loadTableModel(String pCsvFilePath, boolean pHasHeaders)
          Deprecated.  
 TableModel loadTableModelFromString(String pCsvData, boolean pHasHeaders)
          Deprecated.  
static CsvSpec makeExcelSpec()
          Return a CsvSpec instance suitable for loading and creating CSV files that are compatible with Excel.
 CsvLoader makeLoader(Object pSource)
          Make a new CsvLoader for loading in CSV data.
static CsvSpec makeMacSpec()
          Return a CsvSpec instance suitable for loading and creating CSV files that are Mac friendly.
static CsvSpec makePasswdSpec()
          Return a CsvSpec instance suitable for loading UNIX passwd files.
 CsvSaver makeSaver(Object pSink)
          Make a new CsvSaver for saving in CSV data.
static CsvSpec makeUnixSpec()
          Return a CsvSpec instance suitable for loading and creating CSV files that are UNIX friendly.
 void save(File pCsvFile, LineProvider pLineProvider)
          Deprecated.
 void save(File pCsvFile, List pData)
          Deprecated.
 void save(File pCsvFile, ResultSet pData, boolean pSaveHeaders)
          Deprecated.  
 void save(File pCsvFile, TableModel pData, boolean pSaveHeaders)
          Deprecated.  
 void save(Object pSink, LineProvider pLineProvider)
          Save CSV data using your own LineListener.
 void save(Object pSink, LineSpec pLineSpec, LineProvider pLineProvider)
          Save CSV data using your own LineProvider.
 void save(Object pSink, LineSpec pLineSpec, List pData)
          Save CSV data as a List of String[] arrays.
 void save(Object pSink, List pData)
          Save CSV data as a List of String[] arrays.
 void save(OutputStream pOutputStream, LineProvider pLineProvider)
          Deprecated.
 void save(OutputStream pOutputStream, List pData)
          Deprecated.
 void save(OutputStream pOutputStream, ResultSet pData, boolean pSaveHeaders)
          Deprecated.  
 void save(OutputStream pOutputStream, TableModel pData, boolean pSaveHeaders)
          Deprecated.  
 void save(String pCsvFilePath, LineProvider pLineProvider)
          Deprecated.
 void save(String pCsvFilePath, List pData)
          Deprecated.
 void save(String pCsvFilePath, ResultSet pData, boolean pSaveHeaders)
          Deprecated.  
 void save(String pCsvFilePath, TableModel pData, boolean pSaveHeaders)
          Deprecated.  
 void saveAsLists(File pCsvFile, List pData)
          Deprecated.
 void saveAsLists(Object pSink, LineSpec pLineSpec, List pData)
          Save CSV data as a List of Lists of Strings.
 void saveAsLists(Object pSink, List pData)
          Save CSV data as a List of Lists of Strings.
 void saveAsLists(OutputStream pOutputStream, List pData)
          Deprecated.
 void saveAsLists(String pCsvFilePath, List pData)
          Deprecated.
 String saveAsListsToString(List pData)
          Deprecated.  
 void saveBeans(Object pSink, BeanSpec pBeanSpec, List pBeans)
          Save CSV data as a List of Java Beans.
 void saveBeans(Object pSink, LineSpec pLineSpec, BeanSpec pBeanSpec, List pBeans)
          Save CSV data as a List of Java Beans.
 void saveResultSet(Object pSink, LineSpec pLineSpec, ResultSet pData)
          Save CSV data as a ResultSet.
 void saveResultSet(Object pSink, ResultSet pData)
          Save CSV data as a ResultSet.
 void saveTableModel(Object pSink, LineSpec pLineSpec, TableModel pData)
          Save CSV data as a TableModel.
 void saveTableModel(Object pSink, TableModel pData)
          Save CSV data as a TableModel.
 String saveToString(LineProvider pLineProvider)
          Deprecated.  
 String saveToString(List pData)
          Deprecated.  
 String saveToString(ResultSet pData, boolean pSaveHeaders)
          Deprecated.  
 String saveToString(TableModel pData, boolean pSaveHeaders)
          Deprecated.  
 void setCsvSpec(CsvSpec pCsvSpec)
          CsvManager holds an instance of CsvSpec to control the CSV file format.
 void setEncoding(String pEncoding)
          Set the character encoding for input and output.
 void setEndLine(long pEndLine)
          The number of the line at which to stop loading data (inclusive, starts from 1).
 void setEndOfLine(String pEndOfLine)
          Set the end-of-line character or characters.
 void setEscape(char pEscape)
          Set the escape character.
 void setFieldListener(FieldListener pFieldListener)
          Deprecated.  
 void setIgnoreBadLines(boolean pIgnoreBadLines)
          Ignore incorrectly formatted lines and continue processing data lines.
 void setIgnoreEmptyLines(boolean pIgnoreEmptyLines)
          Ignore lines with no data.
 void setNumFields(int pNumFields)
          Optionally set the expected number of data fields per data line.
 void setNumLines(long pNumLines)
          The number of lines to read (use as an alternative to setEndLine(long)).
 void setQuote(char pQuote)
          Set the quote character.
 void setQuoteType(QuoteType pQuoteType)
          Specify how data fields are to quoted when saving.
 void setRunInBackground(boolean pBackground)
          Run the loading or saving process in a separate Thread.
 void setSeparator(String pSeparator)
          Set the separator character.
 void setStartLine(long pStartLine)
          The number of the line from which to start loading data (line numbers start at 1, not 0).
 void setTrimType(TrimType pTrimType)
          Specify how data fields are to quoted when saving.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvManager

public CsvManager()
Create a new instance of CsvManager. This is the main class of the CSV Manager API. To use this class, all you need to do is create a new instance and call one of the load or save methods.


CsvManager

public CsvManager(CsvSpec pCsvSpec)
Create a new instance of CsvManager using the specified CsvSpec CSV format specification.

See Also:
CsvManager(com.ricebridge.csvman.CsvSpec)
Method Detail

load

public List load(Object pSource)
Load CSV data as a List of String[] arrays.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File("mydata.csv");
  CsvManager csvman  = new CsvManager();
  List       data    = csvman.load( csvfile );
  
  for( int line = 0; line < data.size(); line++ ) {
    System.out.println( "line: "+line );
  
    String[] fields = (String[]) data.get(line);
    for( int field = 0; field < fields.length; field++ ) {
      System.out.println( "field "+field+" has value: " + fields[field] );
    }
  }
  

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

For more details about the CSV processing behind this method, see the documentation for BasicLineListener, which is used by this method to store the CSV data that is loaded.

Parameters:
pSource - CSV data source, for example, a File
Returns:
List of String[] arrays.
See Also:
load(Object,LineSpec), BasicLineListener, loadAsLists(Object), loadResultSet(Object), loadTableModel(Object), loadBeans(Object,LineSpec,BeanSpec), load(Object,LineListener)

load

public List load(Object pSource,
                 LineSpec pLineSpec)
Load CSV data as a List of String[] arrays.

For a code example of how to use this method, see load(Object)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are expecting. It is only really useful if you are using a CustomLineListener or loading Java Beans.

Parameters:
pSource - CSV data source, for example, a File
pLineSpec - extra information about the CSV data fields
Returns:
List of String[] arrays.
See Also:
load(Object), BasicLineListener, loadBeans(Object,LineSpec,BeanSpec)

loadAsLists

public List loadAsLists(Object pSource)
Load CSV data as a List of Lists of Strings.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File("mydata.csv");
  CsvManager csvman  = new CsvManager();
  List       data    = csvman.loadAsLists( csvfile );
  
  for( int line = 0; line < data.size(); line++ ) {
    System.out.println( "line: "+line );
  
    List fields = (List) data.get(line);
    for( int field = 0; field < fields.size(); field++ ) {
      System.out.println( "field "+field+" has value: " + fields.get(field) );
    }
  }
  

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

For more details about the CSV processing behind this method, see the documentation for AsListsLineListener, which is used by this method to store the CSV data that is loaded.

Parameters:
pSource - CSV data source, for example, a File
Returns:
List of Lists of Strings
See Also:
loadAsLists(Object,LineSpec), BasicLineListener, load(Object), loadResultSet(Object), loadTableModel(Object), loadBeans(Object,LineSpec,BeanSpec), load(Object,LineListener)

loadAsLists

public List loadAsLists(Object pSource,
                        LineSpec pLineSpec)
Load CSV data as a List of Lists of Strings.

For a code example of how to use this method, see loadAsLists(Object)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are expecting. It is only really useful if you are using a CustomLineListener or loading Java Beans.

Parameters:
pSource - CSV data source, for example, a File
pLineSpec - extra information about the CSV data fields
Returns:
List of Lists of Strings
See Also:
loadAsLists(Object), AsListsLineListener, loadBeans(Object,LineSpec,BeanSpec)

loadTableModel

public TableModel loadTableModel(Object pSource)
Load CSV data as a TableModel.

Here is a code example to demonstrate the use of this method:


  File       csvfile  = new File("mydata.csv");
  CsvManager csvman   = new CsvManager();
  csvman.getCsvSpec().setProperty( "TableModel.dataHasHeaders", true );
  TableModel tm       = csvman.loadTableModel( csvfile );
  JTable     table    = new JTable();
  table.setModel( tm );
  

This method allows you to directly display your data in a Swing application.

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If the first line of your CSV data defines column names, set TableModelLineListener.PROP_TableModel_dataHasHeaders to true using CsvSpec.setProperty. The first line of your CSV data will then become the column names of your data set, and the data returned by the TableModel starts with the second line of the CSV file.

For more details about the CSV processing behind this method, see the documentation for TableModelLineListener, which is used by this method to convert the CSV data into a TableModel.

Parameters:
pSource - CSV data source, for example, a File
Returns:
TableModel
See Also:
loadTableModel(Object,LineSpec), TableModelLineListener, load(Object), loadAsLists(Object), loadResultSet(Object), loadBeans(Object,LineSpec,BeanSpec), load(Object,LineListener)

loadTableModel

public TableModel loadTableModel(Object pSource,
                                 LineSpec pLineSpec)
Load CSV data as a TableModel.

For a code example of how to use this method, see loadTableModel(Object)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are expecting. It is only really useful if you are using a CustomLineListener or loading Java Beans.

Parameters:
pSource - CSV data source, for example, a File
pLineSpec - extra information about the CSV data fields
Returns:
TableModel
See Also:
loadTableModel(Object), TableModelLineListener, loadBeans(Object,LineSpec,BeanSpec)

loadResultSet

public ResultSet loadResultSet(Object pSource)
Load CSV data as a ResultSet.

Here is a code example to demonstrate the use of this method:


  File              csvfile = new File("mydata.csv");
  CsvManager        csvman  = new CsvManager();
  csvman.getCsvSpec().setProperty( "ResultSet.dataHasHeaders", true );
  ResultSet         rs      = csvman.loadResultSet( csvfile );
  ResultSetMetaData md      = rs.getMetaData();
  int               numCols = md.getColumnCount();
  
  for( int col = 1; col <= numCols; col++ ) {
    System.out.print( md.getColumnName(col) + (col<numCols?", ":"\n") );
  }
  while( rs.next() ) {
    for( int col = 1; col <= numCols; col++ ) {
      System.out.print( rs.getString(col) + (col<numCols?", ":"\n") );
    }
  }
  

This method allows you to access your data as if it came from a database.

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If the first line of your CSV data defines column names, set ResultSetLineListener.PROP_ResultSet_dataHasHeaders to true using CsvSpec.setProperty. The first line of your CSV data will then become the column names of your data set, and the data returned by the ResultSet starts with the second line of the CSV file.

For more details about the CSV processing behind this method, see the documentation for ResultSetLineListener, which is used by this method to convert the CSV data into a ResultSet.

Parameters:
pSource - CSV data source, for example, a File
Returns:
ResultSet
See Also:
loadResultSet(Object,LineSpec), ResultSetLineListener, load(Object), loadAsLists(Object), loadTableModel(Object), loadBeans(Object,LineSpec,BeanSpec), load(Object,LineListener)

loadResultSet

public ResultSet loadResultSet(Object pSource,
                               LineSpec pLineSpec)
Load CSV data as a ResultSet.

For a code example of how to use this method, see loadResultSet(Object)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are expecting. It is only really useful if you are using a CustomLineListener or loading Java Beans.

Parameters:
pSource - CSV data source, for example, a File
pLineSpec - extra information about the CSV data fields
Returns:
ResultSet
See Also:
loadResultSet(Object), ResultSetLineListener, loadBeans(Object,LineSpec,BeanSpec)

loadBeans

public List loadBeans(Object pSource,
                      BeanSpec pBeanSpec)
Load CSV data into a List of Java Beans.

This method assumes that the first row of the CSV file contains the bean property names. For a code example and explanation of the pBeanSpec parameter, see loadBeans(Object,LineSpec,BeanSpec)

Parameters:
pSource - CSV data source
pBeanSpec - Java bean specification
Returns:
List of Java Beans
See Also:
loadBeans(Object, LineSpec, BeanSpec)

loadBeans

public List loadBeans(Object pSource,
                      LineSpec pLineSpec,
                      BeanSpec pBeanSpec)
Load CSV data as a List of Java Beans.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File( "mydata.csv" );
  CsvManager csvman  = new CsvManager();
  
  LineSpec ls = new LineSpec( new String[] {"Name","Foo","Bar"} );
  BeanSpec bs = new BeanSpec( BeanRecord.class );
  
  List beans = csvman.loadBeans( csvfile, ls, bs );
  System.out.println( beans.toString() );
  
  // You'll also need this class definition
  public static class BeanRecord {
    private String iName, iFoo, iBar;
  
    public BeanRecord( String pName, String pFoo, String pBar ) {
      iName = pName; iFoo  = pFoo; iBar  = pBar;
    }
    
    public void setName( String pName ) { iName = pName; }
    public String getName() { return iName; }
    public void setFoo( String pFoo ) { iFoo = pFoo; }
    public String getFoo() { return iFoo; }
    public void setBar( String pBar ) { iBar = pBar; }
    public String getBar() { return iBar; }
  
    public String toString() {
      return iName+":"+iFoo+":"+iBar;
    }
  }
  

This method allows you to access your data as a set of Java Bean objects.

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

You specify the property method names using a LineSpec. The property method names are the root names of the property methods, that is, with the get/set/is prefix removed. They should be in the same order as the data fields in the CSV file. Providing a LineSpec is optional, see loadBeans(Object,BeanSpec).

You specify the bean object using a BeanSpec. For more details on specifying the bean properties, see BeanSpec. The BeanSpec is required.

You can control the response to invalid data by using the BeanLineListener.PROP_Bean_useDefault property. When true, invalid data is replaced with the default value for that data type. When false, an Exception is thrown. Set this property like so:


    CsvSpec cs = csvManager.getCsvSpec();
    cs.setProperty("Bean.useDefault",true);
  

Limitations

Java Beans support in CSV Manager is intended only for bean properties. Object graphs are not saved, and thus event listeners and so on are also not saved. CSV Manager does support normal get/set properties, boolean properties and indexed properties. For standard Java types, such as int and double and so on, CSV Manager performs automatic conversion between the textual representation of the data type, and the internal Java variable. For more complex objects, you can define your own conversions, using a StringConverter.

For more details about the CSV processing behind this method, see the documentation for BeanLineListener, which is used by this method to convert the CSV data into Java Beans.

Parameters:
pSource - CSV data source
pLineSpec - in this case, specifies the bean property names
pBeanSpec - Java Bean specification
Returns:
List of Java Beans
Since:
1.2.1
See Also:
loadBeans(Object,BeanSpec), BeanLineListener, load(Object), loadAsLists(Object), loadTableModel(Object), loadResultSet(Object), load(Object,LineListener)

load

public void load(Object pSource,
                 LineListener pLineListener)
Load CSV data using your own LineListener.

Here is a code example to demonstrate the use of this method:


  public class MyLineListener extends CustomLineListener {
    public BadLine addLineImpl( String[] pLine, int pNumFields, long pLineNumber, String pOriginalLine ) {
      System.out.print( "LINE:"+pLineNumber+": " );
      for( int field = 0; field < pNumFields; field++ ) {
        System.out.print( "FIELD "+field+":"+pLine[field] + (field < pNumFields-1?", ":"\n") );
      }
      return null;
    }
  }
    
  public void loadCsv( File pCsvFile ) { 
    File           csvfile = new File( "mydata.csv" );
    CsvManager     csvman  = new CsvManager();
    MyLineListener myln    = new MyLineListener();
    csvman.load( csvfile, myln );
  }
  

This method allows you to access your data in a flexible and customised manner. You get to provide your own handling and storage of the CSV data as it is loaded. See LineListener for a more detailed discussion of this approach.

You can use this method to load CSV data from:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data source object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

The secret to writing a custom LineListener is to copy an existing one! That's why we've made the source code to our own internal LineListeners available, so that you can see how it's done. If you look at the API documentation for each LineListener, you'll find a Source Code link which will take you to the source code. Here's the list:

You can also find some examples of custom LineListeners in the example code.

Parameters:
pSource - CSV data source, for example, a File
pLineListener - a LineListener to receive data
See Also:
LineListener, CustomLineListener, load(Object,LineListener), load(Object), loadAsLists(Object), loadTableModel(Object), loadResultSet(Object), loadBeans(Object,LineSpec,BeanSpec)

load

public void load(Object pSource,
                 LineSpec pLineSpec,
                 LineListener pLineListener)
Load CSV data using your own LineListener.

For a code example of how to use this method, see loadResultSet(Object)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are expecting. It is only really useful if you are using a CustomLineListener or loading Java Beans.

Parameters:
pSource - CSV data source, for example, a File
pLineSpec - extra information about the CSV data fields
pLineListener - a LineListener to receive data
See Also:
LineListener, CustomLineListener, load(Object,LineListener), load(Object), loadAsLists(Object), loadTableModel(Object), loadResultSet(Object), loadBeans(Object,LineSpec,BeanSpec)

makeLoader

public CsvLoader makeLoader(Object pSource)
Make a new CsvLoader for loading in CSV data.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File( "mydata.csv" );
  CsvManager csvman  = new CsvManager();
  CsvLoader  loader  = csvman.makeLoader( csvfile );

  loader.begin();
  while( loader.hasNext() ) {
    String[] fields = loader.next();

    for( int field = 0; field < fields.length; field++ ) {
      System.out.print( fields[field]+", " );
    }
    System.out.println();
  }
  loader.end();
  

See the CsvLoader class for more information about CsvLoaders.

The pSource object can be:

The pSource parameter is an Object so that you can easily use any of these data sources with the same method. This means that you only have to learn about one method for loading data from different places. It also means we can add new types of data source in future versions of CSV Manager without adding more and more methods. For more information see the Sources of CSV Data section above.

For a more detailed example of how to use this method, take a look at the streaming section of the database example

This method allows you to pull CSV data in as a stream. For event-based loading of CSV files, see LineListener. For direct loading, see load(Object).

If there is a problem, this method will throw a CsvManagerException, which is a RuntimeException, so you are not forced to catch it if you don't want to.

Parameters:
pSource - source of the CSV data (more about data sources)
See Also:
CsvLoader, load(Object), loadAsLists(Object), loadTableModel(Object), loadResultSet(Object), load(Object,LineListener), loadBeans(Object,LineSpec,BeanSpec), makeSaver(Object)

save

public void save(Object pSink,
                 List pData)
Save CSV data as a List of String[] arrays.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File("mydata.csv");
  CsvManager csvman  = new CsvManager();
  
  ArrayList data = new ArrayList();
  data.add( new String[] {"Number","Name"} );
  data.add( new String[] {"1","one"} );
  data.add( new String[] {"2","two"} );
  data.add( new String[] {"3","three"} );
  
  csvman.save( csvfile, data );
  

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

To output data field headers as the first line of your CSV file, just place the headers in a String[] array at the start of the List of lines. Headers do not need special treatment - they are just the first line of text data.

For more details about the CSV processing behind this method, see the documentation for BasicLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pData - CSV data to save, a List of String[] arrays
See Also:
save(Object,LineSpec,List), BasicLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

save

public void save(Object pSink,
                 LineSpec pLineSpec,
                 List pData)
Save CSV data as a List of String[] arrays.

For a code example of how to use this method, see save(Object,List)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. It is only really useful if you are using a CustomLineProvider or saving Java Beans.

See the LineProvider.setLineSpec method for more information.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
pData - CSV data to save, a List of String[] arrays
See Also:
save(Object,List), BasicLineProvider, CustomLineProvider

saveAsLists

public void saveAsLists(Object pSink,
                        List pData)
Save CSV data as a List of Lists of Strings.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    
    ArrayList line = null;
    ArrayList data = new ArrayList();
    line = new ArrayList(); line.add("Number"); line.add("Name"); data.add( line );
    line = new ArrayList(); line.add("1"); line.add("one"); data.add( line );
    line = new ArrayList(); line.add("2"); line.add("two"); data.add( line );
    line = new ArrayList(); line.add("3"); line.add("three"); data.add( line );
    
    csvman.saveAsLists( csvfile, data );
    

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

To output data field headers as the first line of your CSV file, just place the headers in a String[] array at the start of the List of lines. Headers do not need special treatment - they are just the first line of text data.

For more details about the CSV processing behind this method, see the documentation for AsListsLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pData - CSV data to save, a List of Lists of Strings
See Also:
saveAsLists(Object,LineSpec,List), AsListsLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

saveAsLists

public void saveAsLists(Object pSink,
                        LineSpec pLineSpec,
                        List pData)
Save CSV data as a List of Lists of Strings.

For a code example of how to use this method, see saveAsLists(Object,List)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. It is only really useful if you are using a CustomLineProvider or saving Java Beans.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
pData - CSV data to save, a List of Lists of Strings
See Also:
saveAsLists(Object,List), AsListsLineProvider, CustomLineProvider

saveResultSet

public void saveResultSet(Object pSink,
                          ResultSet pData)
Save CSV data as a ResultSet.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    Connection con     = getDatabaseConnection(); // return a java.sql.Connection

    // assume a Product table in database
    PreparedStatement ps  
       = con.prepareStatement( "SELECT * FROM Product" ); 

    ResultSet rs = ps.executeQuery();
    csvman.saveResultSet( csvfile, rs );
    

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If you would like to output the table column names as CSV headers, set ResultSetLineProvider.PROP_ResultSet_saveHeaders to true using CsvSpec.setProperty. The first line of your CSV file will then contain the column names of your data set, and the data rows in the ResultSet start on the second line of the CSV file.

For more details about the CSV processing behind this method, see the documentation for ResultSetLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pData - CSV data to save, a ResultSet
See Also:
saveResultSet(Object,LineSpec,ResultSet), ResultSetLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

saveResultSet

public void saveResultSet(Object pSink,
                          LineSpec pLineSpec,
                          ResultSet pData)
Save CSV data as a ResultSet.

For a code example of how to use this method, see saveResultSet(Object,ResultSet)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. It is only really useful if you are using a CustomLineProvider or saving Java Beans.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
See Also:
saveResultSet(Object,ResultSet), ResultSetLineProvider, CustomLineProvider

saveTableModel

public void saveTableModel(Object pSink,
                           TableModel pData)
Save CSV data as a TableModel.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File("mydata.csv");
  CsvManager csvman  = new CsvManager();
  
  JTable myJTable 
    = new JTable( 
        new Object[][] { { "1", "one" }, 
                         { "2", "two" }, 
                         { "3", "three" } },
        new Object[] { "Number", "Name" } );
  
  TableModel tm = myJTable.getModel();
  csvman.saveTableModel( csvfile, tm );
  

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If you would like to output the table column names as CSV headers, set TableModelLineProvider.PROP_TableModel_saveHeaders to true using CsvSpec.setProperty. The first line of your CSV file will then contain the column names of your table, and the rows in the TableModel start on the second line of the CSV file.

For more details about the CSV processing behind this method, see the documentation for TableModelLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pData - CSV data to save, a TableModel
See Also:
saveTableModel(Object,LineSpec,TableModel), TableModelLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

saveTableModel

public void saveTableModel(Object pSink,
                           LineSpec pLineSpec,
                           TableModel pData)
Save CSV data as a TableModel.

For a code example of how to use this method, see saveTableModel(Object,TableModel)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. It is only really useful if you are using a CustomLineProvider or saving Java Beans.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
See Also:
saveTableModel(Object,TableModel), TableModelLineProvider, CustomLineProvider

saveBeans

public void saveBeans(Object pSink,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save CSV data as a List of Java Beans.

Here is a code example to demonstrate the use of this method:


    File       csvFile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();

    LineSpec rs = new LineSpec( new String[] {"Name","Foo","Bar"} );
    BeanSpec bs = new BeanSpec( BeanRecord.class );

    ArrayList beans = new ArrayList();
    beans.add( new BeanRecord("r1","f1","b1") );
    beans.add( new BeanRecord("r2","f2","b2") );
    beans.add( new BeanRecord("r3","f3","b3") );

    csvman.saveBeans( csvFile, rs, bs, beans );

    // You'll also need this class definition
    public static class BeanRecord {
      private String iName, iFoo, iBar;
  
      public BeanRecord( String pName, String pFoo, String pBar ) {
        iName = pName; iFoo  = pFoo; iBar  = pBar;
      }
      
      public void setName( String pName ) { iName = pName; }
      public String getName() { return iName; }
      public void setFoo( String pFoo ) { iFoo = pFoo; }
      public String getFoo() { return iFoo; }
      public void setBar( String pBar ) { iBar = pBar; }
      public String getBar() { return iBar; }

      public String toString() {
        return iName+":"+iFoo+":"+iBar;
      }
    }
    

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

If you would like to output the bean property names as CSV headers, set BeanLineProvider.PROP_Bean_saveHeaders to true using CsvSpec.setProperty. The first line of your CSV file will then contain the property names of your bean, and the bean data rows start on the second line of the CSV file.

This method will generate the bean property names automatically from the bean property methods. The bean property names will then be sorted alphabetically. To specify a subset of the bean properties to output, or to specify your own ordering, use the saveBeans(Object,LineSpec,BeanSpec,List) method, which includes a pLineSpec parameter that lets you control the bean properties.

For more details about the CSV processing behind this method, see the documentation for BeanLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pBeanSpec - Java Bean specification
pBeans - List of Java Beans
See Also:
saveBeans(Object,LineSpec,BeanSpec,List), BeanLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

saveBeans

public void saveBeans(Object pSink,
                      LineSpec pLineSpec,
                      BeanSpec pBeanSpec,
                      List pBeans)
Save CSV data as a List of Java Beans.

For a code example of how to use this method, see saveBeans(Object,LineSpec,BeanSpec,List)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. You can use it to specify the exact list of bean properties to output, and the order in which they should appear. Bean property names must match the bean property methods, but with the get/set/is prefix removed. They should be capitalised.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
pBeanSpec - Java Bean specification
pBeans - List of Java Beans
See Also:
saveBeans(Object,BeanSpec,List), BeanLineProvider, CustomLineProvider

save

public void save(Object pSink,
                 LineProvider pLineProvider)
Save CSV data using your own LineListener.

Here is a code example to demonstrate the use of this method:


  StringsProvider sp 
    = new StringsProvider( new String[][] { 
      { "1", "one" }, 
      { "2", "two" }, 
      { "3", "three" } } );
    
  File       csvfile = new File("mydata.csv");
  CsvManager csvman = new CsvManager();
    
  csvman.save( csvfile, sp );

  // You'll also need this class definition
  public static class StringsProvider extends CustomLineProvider {
    private String[][] iData;
    private int        iIndex = 0;
    
    public StringsProvider( String[][] pData ) {
      iData = pData;
    }
    
    protected boolean hasNextLineImpl() throws Exception {
      return iIndex < iData.length;
    }

    protected String[] nextLineImpl() throws Exception {
      String[] line = iData[iIndex];
      iIndex++;
      return line;
    }
  }
  

You can use this method to save CSV data to the following data sinks (using the pSink parameter):

The pSink parameter is an Object so that you can easily use any of these data sinks with the same method. This means that you only have to learn about one method for saving data to different places. It also means we can add new types of data sink in future versions of CSV Manager without adding more and more methods. For more information see the Destinations for CSV Data section above.

Compatibility note: In CSV Manager 1.1 each data sink object had it's own method. These methods are still available in the CSV Manager 1.x product line but we do not recommend that you use them in new code. Old code will still work of course. These methods are now deprecated and will be removed in CSV Manager 2.x.

To output data field headers as the first line of your CSV file, just return the headers as the first String[] array from your ListListener. Headers do not need special treatment - they are just the first line of text data.

For more details about the CSV processing behind this method, see the documentation for CustomLineProvider, which is used by this method to supply the CSV data that is saved.

Parameters:
pSink - CSV data sink, for example, a File
pLineProvider - a LineProvider to supply data
See Also:
save(Object,LineSpec,LineProvider), CustomLineProvider, saveAsLists(Object,List), saveResultSet(Object,ResultSet), saveTableModel(Object,TableModel), saveBeans(Object,LineSpec,BeanSpec,List), save(Object,LineProvider)

save

public void save(Object pSink,
                 LineSpec pLineSpec,
                 LineProvider pLineProvider)
Save CSV data using your own LineProvider.

For a code example of how to use this method, see save(Object,LineProvider)

The additional pLineSpec parameter in this method allows you to provide extra information about the CSV data fields you are supplying. It is only really useful if you are using a CustomLineProvider or saving Java Beans.

Parameters:
pSink - CSV data sink, for example, a File
pLineSpec - extra information about the CSV data fields
pLineProvider - a LineProvider to supply data
See Also:
save(Object,LineProvider), BasicLineProvider, CustomLineProvider

makeSaver

public CsvSaver makeSaver(Object pSink)
Make a new CsvSaver for saving in CSV data.

Here is a code example to demonstrate the use of this method:


  File       csvfile = new File( "mydata.csv" );
  CsvManager csvman  = new CsvManager();
  CsvSaver   saver   = csvman.makeSaver( csvfile );

  ArrayList data = new ArrayList();
  data.add( new String[] {"1","a","AA"} );
  data.add( new String[] {"2","b","BB"} );
  
  saver.begin();
  for( Iterator lineI = data.iterator(); lineI.hasNext(); ) {
    String[] fields = (String[]) lineI.next();
    saver.next( fields );
  }
  saver.end();
  

See the CsvSaver class for more information about CsvSavers.

The pSink object can be a:

The pSink parameter is an Object so that you only have to learn about one method definition (rather than having one method for each type of sink), and so that we easily can add more data sinks in the future.

For a more detailed example of how to use this method, take a look at the streaming section of the database example

This method allows you to push CSV data out as a stream. For event-based saving of CSV files, see LineProvider. For direct saving, see save(Object,List).

If there is a problem, this method will throw a CsvManagerException, which is a RuntimeException, so you are not forced to catch it if you don't want to.

Parameters:
pSink - destination of the CSV data (more about data sinks)
See Also:
CsvSaver, save(Object,List), LineProvider, makeLoader(Object)

load

public List load(File pCsvFile)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object) instead for new code.

Load CSV data from a file as a List of String[] arrays.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    List       data    = csvman.load( csvfile );

    for( int line = 0; line < data.size(); line++ ) {
      System.out.println( "line: "+line );

      String[] fields = (String[]) data.get(line);
      for( int field = 0; field < fields.length; field++ ) {
        System.out.println( "field "+field+" has value: " + fields[field] );
      }
    }
  

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to load
See Also:
load(String), load(InputStream), loadFromString(String)

load

public List load(String pCsvFilePath)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object) instead for new code.

Load CSV data from a specified file path as a List of String[] arrays.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example, see load(File) (replace File with String).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of CSV file to load
See Also:
load(File)

load

public List load(InputStream pInputStream)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object) instead for new code.

Load CSV data from an InputStream as a List of String[] arrays.

This method allows you to use an InputStream instead of a file as the source of your CSV data. For a code example, see load(File) (replace File with InputStream).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pInputStream - InputStream providing CSV data
See Also:
load(File)

loadFromString

public List loadFromString(String pCsvData)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object) instead for new code.

Load CSV data directly from a String variable as a List of String[] arrays.

This method allows you to use CSV data from an internal String variable instead of loading it from an external file. For a code example, see load(File) (replace File with InputStream).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Parameters:
pCsvData - String containing CSV data
See Also:
load(File)

loadAsLists

public List loadAsLists(File pCsvFile)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadAsLists(Object) instead for new code.

Load CSV data from a file as a List of Lists of Strings.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    List       data    = csvman.loadAsLists( csvfile );

    for( int line = 0; line < data.size(); line++ ) {
      System.out.println( "line: "+line );

      List fields = (List) data.get(line);
      for( int field = 0; field < fields.size(); field++ ) {
        System.out.println( "field "+field+" has value: " + fields.get(field) );
      }
    }
  
You may prefer this data structure to the List of String[] arrays returned by load(File) as it is more flexible.

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to load
See Also:
loadAsLists(String), loadAsLists(InputStream), loadAsListsFromString(String)

loadAsLists

public List loadAsLists(String pCsvFilePath)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadAsLists(Object) instead for new code.

Load CSV data from a specified file path as a List of Lists of Strings.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example, see loadAsLists(File) (replace File with String).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of CSV file to load
See Also:
loadAsLists(File)

loadAsLists

public List loadAsLists(InputStream pInputStream)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadAsLists(Object) instead for new code.

Load CSV data from an InputStream as a List of Lists of Strings.

This method allows you to use an InputStream instead of a file as the source of your CSV data. For a code example, see loadAsLists(File) (replace File with InputStream).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pInputStream - InputStream providing CSV data
See Also:
load(File)

loadAsListsFromString

public List loadAsListsFromString(String pCsvData)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadAsLists(Object) instead for new code.

Load CSV data directly from a String variable as a List of Lists of Strings.

This method allows you to use CSV data from an internal String variable instead of loading it from an external file. For a code example, see loadAsLists(File) (replace File with String).

Note: if the first line of your CSV data defines column headers, then these are provided as the first line of loaded data. Headers are not treated differently from normal data lines when loading using Lists.

Parameters:
pCsvData - String containing CSV data
See Also:
load(File)

loadTableModel

public TableModel loadTableModel(File pCsvFile,
                                 boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadTableModel(Object) instead for new code.

Load CSV data from a file as a TableModel.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    TableModel tm      = csvman.loadTableModel( csvfile, true );
    JTable     table   = new JTable();
    table.setModel( tm );
  
This method allows you to directly display your data in a Swing application.

If the first line of your CSV data defines column headers, set pHasHeaders to true. The first line of your CSV data will then become the column headers of your table, and the data displayed in the table starts with the second line of the CSV file.

Parameters:
pCsvFile - CSV file to load
pHasHeaders - first line of CSV file consists of column headers
See Also:
loadTableModel(String,boolean), loadTableModel(InputStream,boolean), loadTableModelFromString(String,boolean)

loadTableModel

public TableModel loadTableModel(String pCsvFilePath,
                                 boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadTableModel(Object) instead for new code.

Load CSV data from a specified file path as a TableModel.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example and explanation of the pHasHeaders parameter, see loadTableModel(File,boolean)

Parameters:
pCsvFilePath - path of CSV file to load
pHasHeaders - first line of CSV file consists of column headers
See Also:
loadTableModel(File,boolean)

loadTableModel

public TableModel loadTableModel(InputStream pInputStream,
                                 boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadTableModel(Object) instead for new code.

Load CSV data from an InputStream as a TableModel.

This method allows you to use an InputStream instead of a file as the source of your CSV data. For a code example and explanation of the pHasHeaders parameter, see loadTableModel(File,boolean)

Parameters:
pInputStream - InputStream providing CSV data
pHasHeaders - first line of CSV data consists of column headers
See Also:
loadTableModel(File,boolean)

loadTableModelFromString

public TableModel loadTableModelFromString(String pCsvData,
                                           boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadTableModel(Object) instead for new code.

Load CSV data from a String variable as a TableModel.

This method allows you to use CSV data from an internal String variable instead of loading it from an external file. For a code example and explanation of the pHasHeaders parameter, see loadTableModel(File,boolean)

Parameters:
pCsvData - String containing CSV data
pHasHeaders - first line of CSV data consists of column headers
See Also:
loadTableModel(File,boolean)

loadResultSet

public ResultSet loadResultSet(File pCsvFile,
                               boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadResultSet(Object) instead for new code.

Load CSV data from a file as a ResultSet.

Here is a code example to demonstrate the use of this method:


    File              csvfile = new File("mydata.csv");
    CsvManager        csvman  = new CsvManager();
    ResultSet         rs      = csvman.loadResultSet( csvfile, true );
    ResultSetMetaData md      = rs.getMetaData();
    int               numCols = md.getColumnCount();

    for( int col = 1; col <= numCols; col++ ) {
      System.out.print( md.getColumnName(col) + (col<numCols?", ":"\n") );
    }
    while( rs.next() ) {
      for( int col = 1; col <= numCols; col++ ) {
        System.out.print( rs.getString(col) + (col<numCols?", ":"\n") );
      }
    }
  
This method allows you to access your data as if it came from a database.

If the first line of your CSV data defines column names, set pHasHeaders to true. The first line of your CSV data will then become the column names of your data set, and the data returned by the ResultSet starts with the second line of the CSV file.

Parameters:
pCsvFile - CSV file to load
pHasHeaders - first line of CSV file consists of column names
See Also:
loadResultSet(String,boolean), loadResultSet(InputStream,boolean), loadResultSetFromString(String,boolean)

loadResultSet

public ResultSet loadResultSet(String pCsvFilePath,
                               boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadResultSet(Object) instead for new code.

Load CSV data from a specified file path as a ResultSet.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example and explanation of the pHasHeaders parameter, see loadResultSet(File,boolean)

Parameters:
pCsvFilePath - path of CSV file to load
pHasHeaders - first line of CSV file consists of column names
See Also:
loadResultSet(File,boolean)

loadResultSet

public ResultSet loadResultSet(InputStream pInputStream,
                               boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadResultSet(Object) instead for new code.

Load CSV data from an InputStream as a ResultSet.

This method allows you to use an InputStream instead of a file as the source of your CSV data. For a code example and explanation of the pHasHeaders parameter, see loadResultSet(File,boolean)

Parameters:
pInputStream - InputStream providing CSV data
pHasHeaders - first line of CSV data consists of column names
See Also:
loadResultSet(File,boolean)

loadResultSetFromString

public ResultSet loadResultSetFromString(String pCsvData,
                                         boolean pHasHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use loadResultSet(Object) instead for new code.

Load CSV data from a String variable as a ResultSet.

This method allows you to use CSV data from an internal String variable instead of loading it from an external file. For a code example and explanation of the pHasHeaders parameter, see loadResultSet(File,boolean)

Parameters:
pCsvData - String containing CSV data
pHasHeaders - first line of CSV data consists of column names
See Also:
loadResultSet(File,boolean)

load

public void load(File pCsvFile,
                 LineListener pLineListener)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object,LineListener) instead for new code.

Load CSV data from a file using your own LineListener.

Here is a code example to demonstrate the use of this method:


    public class MyLineListener extends LineListenerSupport {
      public void startLoadImpl() { System.out.println( "START" ); }
      public void endLoadImpl() {   System.out.println( "END" ); }

      public BadLine addLineImpl( String[] pLine, int pNumFields, long pLineNumber, String pOriginalLine ) {
        System.out.print( "LINE:"+pLineNumber+": " );
        for( int field = 0; field < pNumFields; field++ ) {
          System.out.print( "FIELD "+field+":"+pLine[field] + (field < pNumFields-1?", ":"\n") );
        }
        return null;
      }
    }
      
    public void loadCsv( File pCsvFile ) { 
      File           csvfile = new File( "mydata.csv" );
      CsvManager     csvman = new CsvManager();
      MyLineListener myln   = new MyLineListener();
      csvman.load( csvfile, myln );
    }
  
This method allows you to access your data in a flexible and customised manner by providing your own handling and storage of the CSV data as it is loaded. See LineListener for a more detailed discussion of this approach.

Note: you can use setRunInBackground(boolean) to load the CSV data in a separate Thread.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to load
pLineListener - LineListener to receive data
See Also:
LineListener, load(File)

load

public void load(String pCsvFilePath,
                 LineListener pLineListener)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object,LineListener) instead for new code.

Load CSV data from a specified file path using your own LineListener.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example of how to use a LineListener, see load(File,LineListener)

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of CSV file to load
pLineListener - LineListener to receive data
See Also:
load(File,LineListener)

load

public void load(InputStream pInputStream,
                 LineListener pLineListener)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object,LineListener) instead for new code.

Load CSV data from an InputStream using your own LineListener.

This method allows you to use an InputStream instead of a file as the source of your CSV data. For a code example of how to use a LineListener, see load(File,LineListener)

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pInputStream - InputStream providing CSV data
pLineListener - LineListener to receive data
See Also:
load(File,LineListener)

loadFromString

public void loadFromString(String pCsvData,
                           LineListener pLineListener)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use load(Object,LineListener) instead for new code.

Load CSV data from a String variable using your own LineListener.

This method allows you to use CSV data from an internal String variable instead of loading it from an external file. For a code example of how to use a LineListener, see load(File,LineListener)

Parameters:
pCsvData - String containing CSV data
pLineListener - LineListener to receive data
See Also:
load(File,LineListener)

save

public void save(File pCsvFile,
                 List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,List) instead for new code.

Save CSV data to a file from a List of String[] arrays.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    List       data    = getMyData(); // return List of String[]
    csvman.save( csvfile, data );
  
Note: you will need to implement the getMyData() method before this code snippet will compile.

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to save
pData - CSV data (List of String[] arrays) to save
See Also:
save(String,List), save(OutputStream,List), saveToString(List)

save

public void save(String pCsvFilePath,
                 List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,List) instead for new code.

Save CSV data to a specified file path from a List of String[] arrays.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example, see save(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of file to save CSV data to
pData - CSV data (List of String[] arrays) to save
See Also:
save(File,List)

save

public void save(OutputStream pOutputStream,
                 List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,List) instead for new code.

Save CSV data to an OutputStream from a List of String[] arrays.

This method allows you to save CSV data to an OutputStream instead of to a file. For a code example, see save(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pOutputStream - OutputStream to save CSV data to
pData - CSV data (List of String[] arrays) to save
See Also:
save(File,List)

saveToString

public String saveToString(List pData)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,List) instead for new code.

Save CSV data to a String variable from a List of String[] arrays.

This method allows you to save CSV data directly to an internal String variable instead of to a file. For a code example, see save(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Parameters:
pData - CSV data (List of String[] arrays) to save
Returns:
String containing text in CSV format
See Also:
save(File,List)

saveAsLists

public void saveAsLists(File pCsvFile,
                        List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveAsLists(Object,List) instead for new code.

Save CSV data to a file from a List of Lists of Strings.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    List       data    = getMyData(); // return List of Lists of Strings
    csvman.saveAsLists( csvfile, data );
  
Note: you will need to implement the getMyData() method before this code snippet will compile.

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to save
pData - CSV data (List of Lists of Strings) to save
See Also:
saveAsLists(String,List), saveAsLists(OutputStream,List), saveAsListsToString(List)

saveAsLists

public void saveAsLists(String pCsvFilePath,
                        List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveAsLists(Object,List) instead for new code.

Save CSV data to a specified file path from a List of Lists of Strings.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example, see saveAsLists(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of file to save CSV data to
pData - CSV data (List of Lists of Strings) to save
See Also:
saveAsLists(File,List)

saveAsLists

public void saveAsLists(OutputStream pOutputStream,
                        List pData)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveAsLists(Object,List) instead for new code.

Save CSV data to an OutputStream from a List of Lists of Strings.

This method allows you to save CSV data to an OutputStream instead of to a file. For a code example, see saveAsLists(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pOutputStream - OutputStream to save CSV data to
pData - CSV data (List of Lists of Strings) to save
See Also:
saveAsLists(File,List)

saveAsListsToString

public String saveAsListsToString(List pData)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveAsLists(Object,List) instead for new code.

Save CSV data to a String variable from a List of Lists of Strings.

This method allows you to save CSV data directly to an internal String variable instead of to a file. For a code example, see saveAsLists(File,List)

Note: if the first line of your CSV data defines column headers, then these are simply output as the first line of saved data. Headers are not treated differently from normal data lines.

Parameters:
pData - CSV data (List of Lists of Strings) to save
Returns:
String containing text in CSV format
See Also:
save(File,List)

save

public void save(File pCsvFile,
                 TableModel pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveTableModel(Object,javax.swing.table.TableModel) instead for new code.

Save CSV data to a file from a TableModel.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    TableModel tm      = myJTable.getModel();
    csvman.save( csvfile, tm, true );
  
Note: you will need to provide the myJTable variable before this code snippet will compile.

This method allows you to save your data directly from a Swing application.

If you want the first line of your CSV data to define column headers, set pSaveHeaders to true. The fields of the first line of your CSV data will then come from the TableModel.getColumnName(int) method, and the second and subsequent lines come from the data displayed in the table.

Parameters:
pCsvFile - CSV file to save
pData - CSV data (as TableModel) to save
pSaveHeaders - first line of CSV file consists of column headers
See Also:
save(String,TableModel,boolean), save(OutputStream,TableModel,boolean), saveToString(TableModel,boolean)

save

public void save(String pCsvFilePath,
                 TableModel pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveTableModel(Object,javax.swing.table.TableModel) instead for new code.

Save CSV data to a specified file path from a TableModel.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example and explanation of the pSaveHeaders parameter, see save(File,TableModel,boolean)

Parameters:
pCsvFilePath - path of file to save CSV data to
pData - CSV data (as TableModel) to save
pSaveHeaders - first line of CSV file consists of column headers
See Also:
save(File,TableModel,boolean)

save

public void save(OutputStream pOutputStream,
                 TableModel pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveTableModel(Object,javax.swing.table.TableModel) instead for new code.

Save CSV data to an OutputStream from a TableModel.

This method allows you to save CSV data to an OutputStream instead of to a file.

Parameters:
pOutputStream - OutputStream to save CSV data to
pData - CSV data (as TableModel) to save
pSaveHeaders - first line of CSV file consists of column headers
See Also:
save(File,TableModel,boolean)

saveToString

public String saveToString(TableModel pData,
                           boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveTableModel(Object,javax.swing.table.TableModel) instead for new code.

Save CSV data to a String variable from a TableModel.

This method allows you to save CSV data directly to an internal String variable instead of to a file.

Parameters:
pData - CSV data (as TableModel) to save
pSaveHeaders - first line of CSV file consists of column headers
Returns:
String containing text in CSV format
See Also:
save(File,TableModel,boolean)

save

public void save(File pCsvFile,
                 ResultSet pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveResultSet(Object,ResultSet) instead for new code.

Save CSV data to a file from a ResultSet.

Here is a code example to demonstrate the use of this method:


    File       csvfile = new File("mydata.csv");
    CsvManager csvman  = new CsvManager();
    Connection con     = getDatabaseConnection(); // return a java.sql.Connection

    // assume a Product table in database
    PreparedStatement ps  
       = con.prepareStatement( "SELECT * FROM Product" ); 

    ResultSet rs = ps.executeQuery();
    csvman.save( csvfile, rs, true );
  
Note: you will need to provide the getDatabaseConnection method before this code snippet will compile.

This method allows you to save your data directly from a database using the JDBC API.

If you want the first line of your CSV data to define column names, set pSaveHeaders to true. The fields of the first line of your CSV data will then come from the ResultSetMetaData object returned from the ResultSet.getMetaData() method, and the second and subsequent lines will come from the data presented by the ResultSet.

Parameters:
pCsvFile - CSV file to save
pData - CSV data (as ResultSet) to save
pSaveHeaders - first line of CSV file consists of column names
See Also:
save(String,ResultSet,boolean), save(OutputStream,ResultSet,boolean), saveToString(ResultSet,boolean)

save

public void save(String pCsvFilePath,
                 ResultSet pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveResultSet(Object,ResultSet) instead for new code.

Save CSV data to a specified file path from a ResultSet.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example and explanation of the pSaveHeaders parameter, see save(File,ResultSet,boolean)

Parameters:
pCsvFilePath - path of file to save CSV data to
pData - CSV data (as ResultSet) to save
pSaveHeaders - first line of CSV file consists of column names
See Also:
save(File,ResultSet,boolean)

save

public void save(OutputStream pOutputStream,
                 ResultSet pData,
                 boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveResultSet(Object,ResultSet) instead for new code.

Save CSV data to an OutputStream from a ResultSet.

This method allows you to save CSV data to an OutputStream instead of to a file.

Parameters:
pOutputStream - OutputStream to save CSV data to
pData - CSV data (as ResultSet) to save
pSaveHeaders - first line of CSV file consists of column names
See Also:
save(File,ResultSet,boolean)

saveToString

public String saveToString(ResultSet pData,
                           boolean pSaveHeaders)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use saveResultSet(Object,ResultSet) instead for new code.

Save CSV data to a String variable from a ResultSet.

This method allows you to save CSV data directly to an internal String variable instead of to a file.

Parameters:
pData - CSV data (as ResultSet) to save
pSaveHeaders - first line of CSV file consists of column names
Returns:
String containing text in CSV format
See Also:
save(File,ResultSet,boolean)

save

public void save(File pCsvFile,
                 LineProvider pLineProvider)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,LineProvider) instead for new code.

Save CSV data from a file using your own LineProvider.

Here is a code example to demonstrate the use of this method:


    // assume all business objects implement this interface
    public interface BusinessObject {
      public List makeFieldList(); // copy all data fields into a List of Strings
    }

    public class MyLineProvider extends LineProviderSupport {
      private List           iBusinessObjects;
      private int            iObjectIndex;
      private List           iFields;
      private int            iFieldIndex;

      public MyLineProvider( List pBusinessObjects ) {
        iBusinessObjects = pBusinessObjects;
      }

      public void startSaveImpl() {
        iObjectIndex = 0;
        iFields      = new ArrayList();
      }

      public void endSaveImpl() {}

      public boolean hasNextLineImpl() {
        return iObjectIndex < iBusinessObjects.size();
      }

      public void nextLineImpl() {
        iFields = ((BusinessObject) iBusinessObjects.get(iObjectIndex++)).makeFieldList();
      }

      public boolean hasNextFieldImpl() {
        return iFieldIndex < iFields.size();
      }
      
      public String nextFieldImpl() {
        return (String) iFields.get(iFieldIndex++);
      }
    }
    

    public void saveCsv( File pCsvFile, List pBusinessObjects ) { 
      CsvManager     csvman = new CsvManager();
      MyLineProvider mylp   = new MyLineProvider( pBusinessObjects );
      csvman.save( pCsvFile, mylp );
    }
  
This method allows you to provide your data in a flexible and customised manner for saving. See LineProvider for a more detailed discussion of this approach.

Note: you can use setRunInBackground(boolean) to save the CSV data in a separate Thread.

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFile - CSV file to load
pLineProvider - LineProvider to provide data
See Also:
LineProvider, save(File,List)

save

public void save(String pCsvFilePath,
                 LineProvider pLineProvider)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,LineProvider) instead for new code.

Save CSV data to a specified file path using your own LineProvider.

This method allows you to specify the path to the CSV file using a String instead of creating a File object. For a code example of how to use a LineProvider, see save(File,LineProvider)

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pCsvFilePath - path of CSV file to load
pLineProvider - LineProvider to provide data
See Also:
save(File,LineProvider)

save

public void save(OutputStream pOutputStream,
                 LineProvider pLineProvider)
Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,LineProvider) instead for new code.

Save CSV data to an OutputStream using your own LineProvider.

This method allows you to use an OutputStream instead of a file as the destination for your CSV data. For a code example of how to use a LineProvider, see save(File,LineProvider)

Deprecation note: this method is deprecated, but it is not marked as deprecated to avoid spurious deprecation warnings caused by the fact that it masks a non-deprecated method.

Parameters:
pOutputStream - OutputStream receiving CSV data
pLineProvider - LineProvider to provide data
See Also:
save(File,LineProvider)

saveToString

public String saveToString(LineProvider pLineProvider)
Deprecated.  

Deprecated. DO NOT USE.

This method is included for backwards compatibility only and will be removed in CSV Manager 2.x

Please use save(Object,LineProvider) instead for new code.

Save CSV data to a String variable using your own LineProvider.

This method allows you to save CSV data to an internal String variable instead of saving it to an external file. For a code example of how to use a LineProvider, see save(File,LineProvider)

Parameters:
pLineProvider - LineProvider to provide data
Returns:
String contained text in CSV format
See Also:
save(File,LineProvider)

setEncoding

public void setEncoding(String pEncoding)
Set the character encoding for input and output. See CsvSpec.setEncoding(java.lang.String) for more information.

Parameters:
pEncoding - encoding name
See Also:
CsvSpec.setEncoding(java.lang.String)

setNumFields

public void setNumFields(int pNumFields)
Optionally set the expected number of data fields per data line. See CsvSpec.setNumFields(int) for more information.

Parameters:
pNumFields - number of expected data fields
See Also:
CsvSpec.setNumFields(int)

setSeparator

public void setSeparator(String pSeparator)
Set the separator character. See CsvSpec.setSeparator for more information.

Parameters:
pSeparator - separator character
See Also:
CsvSpec.setSeparator(java.lang.String)

setQuote

public void setQuote(char pQuote)
Set the quote character. See CsvSpec.setQuote for more information.

Parameters:
pQuote - quote character
See Also:
CsvSpec.setQuote(char)

setQuoteType

public void setQuoteType(QuoteType pQuoteType)
Specify how data fields are to quoted when saving. See CsvSpec.setQuoteType for more information.

Parameters:
pQuoteType - quote type
See Also:
CsvSpec.setQuoteType(com.ricebridge.csvman.QuoteType)

setEscape

public void setEscape(char pEscape)
Set the escape character. See CsvSpec.setEscape(char) for more information.

Parameters:
pEscape - escape character
See Also:
CsvSpec.setEscape(char)

setEndOfLine

public void setEndOfLine(String pEndOfLine)
Set the end-of-line character or characters. See CsvSpec.setEndOfLine(java.lang.String) for more information.

Parameters:
pEndOfLine - end-of-line character sequence
See Also:
CsvSpec.setEndOfLine(java.lang.String)

setIgnoreBadLines

public void setIgnoreBadLines(boolean pIgnoreBadLines)
Ignore incorrectly formatted lines and continue processing data lines. See CsvSpec.setIgnoreBadLines(boolean) for more information.

Parameters:
pIgnoreBadLines - ignore bad lines setting
See Also:
CsvSpec.setIgnoreBadLines(boolean)

setIgnoreEmptyLines

public void setIgnoreEmptyLines(boolean pIgnoreEmptyLines)
Ignore lines with no data. See CsvSpec.setIgnoreEmptyLines(boolean) for more information.

Parameters:
pIgnoreEmptyLines - ignore empty lines setting
See Also:
CsvSpec.setIgnoreEmptyLines(boolean)

setTrimType

public void setTrimType(TrimType pTrimType)
Specify how data fields are to quoted when saving. See CsvSpec.setTrimType for more information.

Parameters:
pTrimType - trim type setting
See Also:
CsvSpec.setTrimType(com.ricebridge.csvman.TrimType)

setStartLine

public void setStartLine(long pStartLine)
The number of the line from which to start loading data (line numbers start at 1, not 0). See CsvSpec.setStartLine(long) for more information.

Parameters:
pStartLine - start line value (from 1, not 0)
See Also:
CsvSpec.setStartLine(long)

setEndLine

public void setEndLine(long pEndLine)
The number of the line at which to stop loading data (inclusive, starts from 1). See CsvSpec.setEndLine(long) for more information.

Parameters:
pEndLine - end line value (inclusive)
See Also:
CsvSpec.setEndLine(long), CsvSpec.setNumLines(long)

setNumLines

public void setNumLines(long pNumLines)
The number of lines to read (use as an alternative to setEndLine(long)). See CsvSpec.setNumLines(long) for more information.

Parameters:
pNumLines - number of lines
See Also:
CsvSpec.setEndLine(long)

setFieldListener

public void setFieldListener(FieldListener pFieldListener)
Deprecated.  

Receive notification as each data field is loaded.

A FieldListener implementation can be used at the same time as a LineListener. Set pFieldListener to null to remove a previously set FieldListener. For a code example see DebugFieldListener

Parameters:
pFieldListener - FieldListener implementation
See Also:
FieldListener

getLineCount

public long getLineCount()
Get the number of lines of data loaded or saved.

If the load or save process is running in a separate Thread (see setRunInBackground(boolean)), this method returns the number of lines currently processed.

Note: the line count includes the number of bad lines found.

See Also:
getBadLineCount(), getStatsSummary()

getBadLineCount

public long getBadLineCount()
Get the number of badly formatted lines of data when loading or saving.

If the load or save process is running in a separate Thread (see setRunInBackground(boolean)), this method returns the number of bad lines currently processed.

This method is only valid when setIgnoreBadLines(boolean) is true.

Note: the line count includes the number of bad lines found.

See Also:
getBadLines(), getLineCount(), getStatsSummary()

getBadLines

public List getBadLines()
Get a list of descriptions (BadLine) of any badly formatted data lines encountered.

This method returns a list of BadLine objects, one for each badly formatted data line in the original CSV text. BadLine objects are also create when a processing error occurs inside a LineListener or LineProvider instance.

See Also:
BadLine, getBadLineCount(), getStatsSummary(), LineListener

isFinished

public boolean isFinished()
Returns true when the loading or saving process is finished.

Normally this is only useful when loading or saving as a background process.

See Also:
getStatsSummary()

getAverageTimePerLineInSeconds

public double getAverageTimePerLineInSeconds()
Get the average time taken to process each line in seconds.

This provides a running average if the process is running in the background.

See Also:
getStatsSummary()

getTimeTaken

public long getTimeTaken()
Get the total time in milliseconds taken to process all lines.

This provides a running total if the process is running in the background.

See Also:
getStatsSummary()

getTimeTakenInSeconds

public double getTimeTakenInSeconds()
Get the total time in seconds taken to process all lines.

This provides a running total if the process is running in the background.

See Also:
getStatsSummary()

getStartDate

public Date getStartDate()
Get the Date at which processing started.

See Also:
getStatsSummary()

getEndDate

public Date getEndDate()
Get the Date at which processing of data lines ended.

See Also:
getStatsSummary()

getStatsSummary

public String getStatsSummary()
Get a summary String containing the statistics of the previous or running operation.

An example result String is:

[CSV:Summary:fin=true:lines=22:bad=0:avgsec=0.0005:totalsec=0.01: \
    start=20040813061519:end=20040813061519]
The result String is designed for machine and human readability and has the general format:
[CSV:Summary:fin={boolean}:lines={long}:bad={long}:avgsec={0.####}:totalsec={0.####}: \
    start={yyyyMMddhhmmss}:end={yyyyMMddhhmmss}]

See Also:
getLineCount(), getBadLineCount(), getTimeTaken(), getTimeTakenInSeconds(), getAverageTimePerLineInSeconds(), getStartDate(), getEndDate(), isFinished()

setRunInBackground

public void setRunInBackground(boolean pBackground)
Run the loading or saving process in a separate Thread.

If your data set or file is large or if handling the file is time consuming, then it may make sense to run the loading or saving process into a separate Thread.

By default all processing occurs in the calling code Thread and your code must wait for the load or save operation to complete. If you set the run in background setting to true, then processing is performed in a daemon Thread.

Note: this option is only really useful when you use a LineListener or LineProvider, as the convenience methods such as load(File) wait for all data to load before returning.

Parameters:
pBackground - run process in background
See Also:
getRunInBackground()

getRunInBackground

public boolean getRunInBackground()
Get the status of the run in background setting.

See Also:
setRunInBackground(boolean)

setCsvSpec

public void setCsvSpec(CsvSpec pCsvSpec)
CsvManager holds an instance of CsvSpec to control the CSV file format.

Use this method to set your own CsvSpec instance with your own settings. You can get predefined CsvSpec instances using the make*Spec() convenience methods such as makeUnixSpec(). You can use these as the basis for your own CsvSpec settings.

The default CsvSpec is for Excel.

Parameters:
pCsvSpec - CsvSpec instance
See Also:
getCsvSpec(), CsvSpec

getCsvSpec

public CsvSpec getCsvSpec()
Set the CsvSpec, a specification for CSV file format variation to use.

This method returns the current instance of CsvSpec, so that you can change the CSV file format settings directly. CsvManager also provides convenience methods such as setSeparator(java.lang.String) that actually call the corresponding CsvSpec methods: CsvSpec.setSeparator(java.lang.String).

The default CsvSpec is for Excel.

See Also:
setCsvSpec(com.ricebridge.csvman.CsvSpec), CsvSpec

makeExcelSpec

public static CsvSpec makeExcelSpec()
Return a CsvSpec instance suitable for loading and creating CSV files that are compatible with Excel.

Use the setCsvSpec(com.ricebridge.csvman.CsvSpec) to set the CsvSpec instance returned by this method, like so:


    CsvManager csvman = new CsvManager();
    CsvSpec    spec   = CsvManager.makeExcelSpec();
    csvman.setCsvSpec( spec );
  

See Also:
setCsvSpec(com.ricebridge.csvman.CsvSpec)

makeUnixSpec

public static CsvSpec makeUnixSpec()
Return a CsvSpec instance suitable for loading and creating CSV files that are UNIX friendly.

The end-of-line character is set to \n (newline) with CsvSpec.setEndOfLine(java.lang.String) and backslash escapes such as \n are recognised (CsvSpec.setUseEscape(boolean)).


makePasswdSpec

public static CsvSpec makePasswdSpec()
Return a CsvSpec instance suitable for loading UNIX passwd files.

Based on the CsvSpec returned by makeUnixSpec(), the separator character is set to : using CsvSpec.setSeparator(java.lang.String), quotes are disabled using CsvSpec.setUseQuote(boolean) and the TrimType trim type is set to None with CsvSpec.setTrimType(com.ricebridge.csvman.TrimType).


makeMacSpec

public static CsvSpec makeMacSpec()
Return a CsvSpec instance suitable for loading and creating CSV files that are Mac friendly.

The end-of-line character is set to \r (return) with CsvSpec.setEndOfLine(java.lang.String).


getCsvManagerStore

public CsvManagerStore getCsvManagerStore()
CsvManagerStore is a utility class for handling LineListener and LineProvider instances.

You can use CsvManagerStore to access the default listeners and providers, or set your own defaults. These listeners and providers are used with the four default data models: List of String[], List of Lists of String, TableModel and ResultSet.

See Also:
CsvManagerStore


Copyright © 2003-2006 Ricebridge