Crocus – CSV Reader

Easy to use ready to go CSV File Reading utility. Read One or Multiple files into a RecordManager, quick access to the file with segmentation into Fields and Records. Merge Multiple CSV files in one. Listener to CSV Files.

Download Here

A CSV file is broken up as follows
A CSVField has a group of characters
A CSVRecord has a group of CSVFields
A CSVFile has a group of record

How To Use:

Reading a Single CSVFile into a RecordManager

  1.  // Creating a single file interface
  2. CSVSingleFileInterface fileInterface = new CSVSingleFileInterface("/media/data/dev/workspace/crocus/testData/drupal-sample.csv",CSVConstants.COMMA);
  3. // Calling the read returns a CSVRecordManager i.e. in memory
  4. AbstractCSVRecordManager manager =;

Reading multiple files into one RecordManager

  1. // Specify a FileSet
  2. AbstractCSVFileSet fileSet = new CSVFileSet();
  4. // Add files to the set
  5. fileSet.addFile("testData/drupal-sample.csv");
  6. fileSet.addFile("testData/countries.csv");
  8. // Add the fileSet to a Reading Interface
  9. CSVFileSetInterface fileSetInterface = new CSVFileSetInterface(fileSet);
  11. //  Reading returns a manager same as in a Single file case.
  12. AbstractCSVRecordManager manager =;

This functionality is not complete but a peak is available.
You can now specify a Listener to Pre, Post and On Add of a record.

Setting up a Listener.

To add you listener simply implement the RecordListener class

  1. // Get a Record Manager
  2. AbstractCSVRecordManager manager = fileInterface.getRecordManager();
  4. // Add a listener to the Manager.
  5. manager.addRecordListener(this);
  1. // Implement an event listening method for listening to the RecordEvent.
  2. public void eventPerformed(RecordEvent recordEvent) {
  3. System.out.println(recordEvent.toString());
  5. }

for further information refer to the docs.

The Build System:

The build script supports the following targets

Build: init, clean, compile, jar, javadoc, tests

Including, Excluding files while creating compile, jar, tests

FILE DETAILS (Paths and description):



CROCUS_DEV = the main directory i.e. examples from here onwards this will be the variable used for describing details.

You will need to set CROCUS_DEV env variable inorder to run the build process

Also you would need to set ANT_HOME for usage of ant. I have used Ant 1.6.5 for builds.

$CROCUS_DEV/src Holds the source code i.e. java files

$CROCUS_DEV/build Carries all the build related files

$CROCUS_DEV/build/build.xml Main build script

$CROCUS_DEV/build/include.xml patterns for inclusion of java files at the time of compilation

$CROCUS_DEV/build/exclude.xml patterns for exclusion of java files at the time of compilation

$CROCUS_DEV/build/tests_include.xml patterns for inclusion of test java files at the time of compilation

$CROCUS_DEV/build/tests_exclude.xml patterns for exclusion of test java files at the time of compilation

$CROCUS_DEV/build/tools tools used during build.

$CROCUS_DEV/build/jar_buildfiles you can simply specify a txt file with some wild card matches and name it as yourjar.jar for the build system to recognize that “yourjar.jar” will be the name for this jar that should have the packages in it as specified in this txt(yourjar.jar)

$CROCUS_DEV/build/bin Holds the uniz script and the bat file for developers to run the build script more or less as:

Windows:> %CROCUS_DEV%/build all

Linux:> $CROCUS_DEV/ all

$CROCUS_DEV/build_results Holds all the results of the builds

$CROCUS_DEV/build_results/docs Created java docs

$CROCUS_DEV/build_results/classes Created classes

$CROCUS_DEV/build_results/tests Unit test results

$CROCUS_DEV/build_results/jars the jars created by the system

$CROCUS_DEV/jars/ Is the directory for jars related information

$CROCUS_DEV/jars/manifests Holds the manifests for the $CROCUS_DEV/build/jar_buildfiles.

Conventionally should use: Manifest.jarName

$CROCUS_DEV/jars/original3rdparty Holds any 3rd party vendor jars that might be used for putting in the classpath for the build system

$CROCUS_DEV/testData logically should hold all testData no matter how that might be. currently I have placed a few csv files (tabbed,comma,semicolon).

Quick start Singleton – Walk through

This being my first existence on the network and I just want to make sure that I would come back to this blog page again sometime and keep on writing. For now this is a quick 5 min walk through of getting your hands dirty on the Singleton Pattern. As any ones first pattern Singleton always seems to be the easiest to adapt and ironically always the mistress of your pains; when you realize the act wasn’t right in the first place.
More details on that later.

This post should help you to get your hands right on the Singleton Pattern and find the kind there off.

Like any other pattern Singleton also has an objective behind it. What is that?


A Singleton ensures that a class has only one instance, and provides a global point of access to that class.

The very simple benefits of a singleton can be:

* Controlled access
* Permits a variable number of instances
* Reduced name space

When to use:
There must be exactly once instance of a class

How to use: Walk Through

1. Create a class

  1. public class SimplySingleton{}

2. Declare a member variable. This variable will be used for keeping the singleton instance.

It has to be private so that it is not accessible from anywhere else. It has to be static so that it holds only one instance in all entirety.

  1. private static SimplySingleton simplySingleton = null;

3. Declare a private constructor.

Creating a private constructor would mean no one else can instantiate this class.

  1. private SimplySingleton(){}

4. So now everything seems private how do we access it. Create a global access point.

  1. public static SimplySingleton getInstance(){}

How would I access it from outside SimplySingleton.getInstance();

This method should return a SimplySingleton instance.

So here comes the logic to create the one and only instance.

  1. // 4a. is the variable null?
  2. if(simplySingleton != null)
  3. return simplySingleton;
  4. // 4b. if not assign it an instance.
  5. else return simplySingleton = new SimplySingleton();

Following is the complete code listing for writing a Singleton.

  1. // Declaring the class
  2. public class SimplySingleton {
  4. // 1. a private and a static member variable
  6. private static SimplySingleton simplySingleton = null;
  8. // 2. a private constructor
  10. private SimplySingleton(){}
  12. // 3. a global access point
  14. public static SimplySingleton getInstance(){
  15. // 4a. is the variable null?
  16. if(simplySingleton != null)
  17. return simplySingleton;
  18. // 4b. if not assign it an instance.
  19. else return simplySingleton = new SimplySingleton();
  20. }
  22. }

Following are some good resources for in depth peek into the Singleton Pattern.

More Resources: