<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shaaf's Blog &#187; how-to</title>
	<atom:link href="http://www.shaafshah.com/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaafshah.com</link>
	<description>Another bit in the wall</description>
	<lastBuildDate>Wed, 12 Aug 2009 14:28:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Crocus &#8211; CSV Reader</title>
		<link>http://www.shaafshah.com/2008/10/03/crocus-csv-reader/</link>
		<comments>http://www.shaafshah.com/2008/10/03/crocus-csv-reader/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 21:38:42 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[utils]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=51</guid>
		<description><![CDATA[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 Organization: A CSV file is broken up as follows A CSVField has a group [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p><a title="Download Here" href="https://sourceforge.net/project/platformdownload.php?group_id=172152" target="_self">Download Here<br />
</a></p>
<p><strong>Organization:</strong><br />
A CSV file is broken up as follows<br />
A CSVField has a group of characters<br />
A CSVRecord has a group of CSVFields<br />
A CSVFile has a group of record</p>
<p><strong>How To Use:</strong></p>
<p>Reading a Single CSVFile into a RecordManager</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;">// Creating a single file interface</span>
CSVSingleFileInterface fileInterface <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CSVSingleFileInterface<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/media/data/dev/workspace/crocus/testData/drupal-sample.csv&quot;</span>,CSVConstants.<span style="color: #006633;">COMMA</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Calling the read returns a CSVRecordManager i.e. in memory</span>
AbstractCSVRecordManager manager <span style="color: #339933;">=</span> fileInterface.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Reading multiple files into one RecordManager</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Specify a FileSet</span>
AbstractCSVFileSet fileSet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CSVFileSet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add files to the set</span>
fileSet.<span style="color: #006633;">addFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testData/drupal-sample.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fileSet.<span style="color: #006633;">addFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testData/countries.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add the fileSet to a Reading Interface</span>
CSVFileSetInterface fileSetInterface <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CSVFileSetInterface<span style="color: #009900;">&#40;</span>fileSet<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Reading returns a manager same as in a Single file case.</span>
AbstractCSVRecordManager manager <span style="color: #339933;">=</span> fileSetInterface.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This functionality is not complete but a peak is available.<br />
You can now specify a Listener to Pre, Post and On Add of a record.<br />
<strong><br />
Setting up a Listener.</strong></p>
<p>To add you listener simply implement the RecordListener class</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get a Record Manager</span>
AbstractCSVRecordManager manager <span style="color: #339933;">=</span> fileInterface.<span style="color: #006633;">getRecordManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add a listener to the Manager.</span>
manager.<span style="color: #006633;">addRecordListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Implement an event listening method for listening to the RecordEvent.</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>recordEvent.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>for further information refer to the docs.  <a title="http://www.shaafshah.com/crocus/" href="http://www.shaafshah.com/crocus/" target="_self">http://www.shaafshah.com/crocus/</a></p>
<p><strong>The Build System:</strong></p>
<p>The build script supports the following targets</p>
<p>Build: init, clean, compile, jar, javadoc, tests</p>
<p>Including, Excluding files while creating compile, jar, tests</p>
<p><strong>FILE DETAILS (Paths and description):</strong></p>
<p><strong>PRE RULES:</strong></p>
<p>=========</p>
<p>CROCUS_DEV = the main directory i.e. examples from here onwards this will be the variable used for describing details.</p>
<p>You will need to set CROCUS_DEV env variable inorder to run the build process</p>
<p>Also you would need to set ANT_HOME for usage of ant. I have used Ant 1.6.5 for builds.</p>
<p>$CROCUS_DEV/src Holds the source code i.e. java files</p>
<p>$CROCUS_DEV/build Carries all the build related files</p>
<p>$CROCUS_DEV/build/build.xml Main build script</p>
<p>$CROCUS_DEV/build/include.xml patterns for inclusion of java files at the time of compilation</p>
<p>$CROCUS_DEV/build/exclude.xml patterns for exclusion of java files at the time of compilation</p>
<p>$CROCUS_DEV/build/tests_include.xml patterns for inclusion of test java files at the time of compilation</p>
<p>$CROCUS_DEV/build/tests_exclude.xml patterns for exclusion of test java files at the time of compilation</p>
<p>$CROCUS_DEV/build/tools tools used during build.</p>
<p>$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 &#8220;yourjar.jar&#8221; will be the name for this jar that should have the packages in it as specified in this txt(yourjar.jar)</p>
<p>$CROCUS_DEV/build/bin Holds the uniz script and the bat file for developers to run the build script more or less as:</p>
<p>Windows:&gt; %CROCUS_DEV%/build all</p>
<p>Linux:&gt; $CROCUS_DEV/build.sh all</p>
<p>$CROCUS_DEV/build_results Holds all the results of the builds</p>
<p>$CROCUS_DEV/build_results/docs Created java docs</p>
<p>$CROCUS_DEV/build_results/classes Created classes</p>
<p>$CROCUS_DEV/build_results/tests Unit test results</p>
<p>$CROCUS_DEV/build_results/jars the jars created by the system</p>
<p>$CROCUS_DEV/jars/ Is the directory for jars related information</p>
<p>$CROCUS_DEV/jars/manifests Holds the manifests for the $CROCUS_DEV/build/jar_buildfiles.</p>
<p>Conventionally should use: Manifest.jarName</p>
<p>$CROCUS_DEV/jars/original3rdparty Holds any 3rd party vendor jars that might be used for putting in the classpath for the build system</p>
<p>$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).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/03/crocus-csv-reader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
