Ricebridge
Search This Site
Sep 02 2010 23:08 UTC


$15 Gift Certificate for every bug you find.

MaxMind GeoIP
This IP address to country database is provided as a CSV file that can easily be read by CSV Manager.

Got a question for us?
Just Ask!

Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at del.icio.us Digg Event-Driven Data feature description for Ricebridge Java CSV Manager Component at Digg.com Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at reddit.com Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at YahooMyWeb Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at Spurl.net Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at Simpy.com Bookmark Polyphasic Mutants at NewsVine Blink this Event-Driven Data feature description for Ricebridge Java CSV Manager Component at blinklist.com Bookmark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at Furl.net Fark Event-Driven Data feature description for Ricebridge Java CSV Manager Component at Fark.com

Event-driven Data

CSV Manager can load and save your data using line-by-line events. This allows you to handle very large CSV files.

Code Example

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 code example can load data from a very large CSV file one line at a time. This means that the whole file is not loaded in memory which conserves resources and makes the loading process a lot faster. All you have to do is implement the LineListener interface to receive the data one line at a time.

Use this method when...

  • you cannot load all the data into memory at once.
  • you want to handle the data line-by-line.
  • You receive data batches on a continuous basis.
The load method can take a String containing the file path, or a File object.

What happens when some rows contain more fields than others?

Each data row is passed individually as a String[] array to your code via the addLine method of your LineListener class. Each String[] array always contains enough elements to hold all the data fields found in any one row, so you never lose data.

What happens when some rows are missing fields?

The String[] array passed to your implementation of the addLine method always contains a minimum number of elements. This minimum can be set using the setNumFields method. If not set, the number of fields in the first line is used as the minimum. This minimum is automatically increased (and stays increased) whenever a row containing more fields than the previous minimum is found. For any given line, if the number of data fields is less than the minimum, then the remaining fields are set to empty strings.

OK, how do I get the column headers?

The column headers are simply the first row of data returned. If the column names are not in the first line, then they are either in a predefined line (say line 3), so start loading lines from there using setStartLine, or you can set CSV Manager to ignore empty lines, until you find them.

But my data isn't in a file!

You are not restricted to loading CSV data only from files. You can also load data from Strings (loadFromString(String) method) and from InputStreams (load(InputStream) method). This means that you can use CSV Manager in a completely dynamic way within your application.

What about saving data to a CSV file?

You can also save data to a CSV file one line at a time by implementing the LineProvider interface. This allows you to provide each line of data from your own data source. Here's the example code:

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;
  }
}

See the save method description for more details.

What other data structures can you handle?

We also support:

I need to see something working.

Sure, no problem. Head on over to our online demo and try out CSV Manager on your own data.

I have another question...

If you have a particular question you need answered, just ask! We're happy to explain exactly how CSV Manager works and show you how to use it.

FREE Email Support

All CSV Manager licenses include a FREE 6 month Email Support Package, worth $1500.00.

Email Support Package

FREE XML Manager

All CSV Manager licenses include a FREE XML Manager single developer license, worth $170.00.

Convert CSV to XML

Any CSV Format

The CSV Manager component can handle any style of tabular text data, from Excel CSV files to the UNIX passwd file.

CSV Formats

"Your product actually did help a lot! I was able to accelerate my development time quite a bit and your service support was also real nice."
Luis Garcia,
Independent Contractor
"An event-based CSV parser is so much more flexible and elegant than the free alternatives that I found. We use it for applications which require a mixture of XML and CSV data. This requires a parser that performs well, uses memory efficiently, simplifies data access and accurately formats output data. We found the Ricebridge parser easy to work with, conspicuously well documented and capable of handling large (500kb+) files. That's a big thumbs up from all the Gaisan team."
Shane Dempsey,
Gaisan
"I would have spent all day trying to read CSV fields that contained commas. I bought your software about 15 minutes ago and my problem is ALREADY solved. Thank you very, very much for a quality piece of software."
Adrian Klingel,
Illumaware
"Ricebridge CSV Manager was really easy to integrate into our existing system, and has been completely reliable for data transfer, not to mention a big time saver!"
Fred Crowe, Speech-Writers
comment on this page Home | Search | About Us | Contact Us | Our Products | Documentation | Resources | Login
Copyright © 2004-2010 Ricebridge. All Rights Reserved.