<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Stephen (Steve) Withington - Java</title>
			<link>http://www.stephenwithington.com/blog/index.cfm</link>
			<description>Blog Thoughts and Ramblings of a ColdFusion Programmer/Developer</description>
			<language>en-us</language>
			<pubDate>Wed, 08 Sep 2010 08:55:15 -0700</pubDate>
			<lastBuildDate>Fri, 21 May 2010 09:12:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>steve@stephenwithington.com</managingEditor>
			<webMaster>steve@stephenwithington.com</webMaster>
			
			
			
			
			
			<item>
				<title>Using ColdFusion to Parse CSV via JavaLoader and OpenCSV</title>
				<link>http://www.stephenwithington.com/blog/index.cfm/2010/5/21/Using-ColdFusion-to-Parse-CSV-via-JavaLoader-and-OpenCSV</link>
				<description>
				
				&lt;p&gt;Recently I needed a quick and easy way to parse a CSV file with ColdFusion, and while there are a few projects floating around out in the wild, I had used &lt;a href=&quot;http://opencsv.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;OpenCSV&lt;/a&gt; in the past and remembered how easy it was to use.&lt;/p&gt;
&lt;p&gt;While I&apos;ve seen a few examples for ColdFusion users on how to parse and read a CSV file with OpenCSV, they&apos;ve all used Java&apos;s &lt;a href=&quot;http://java.sun.com/javase/7/docs/api/java/io/FileReader.html&quot; target=&quot;_blank&quot;&gt;FileReader&lt;/a&gt; to do it. This meant you had to have the file stored on your server somewhere and then get the full path to its location. For example, C:\csvfiles\sample.csv. In addition, most all of the examples I&apos;ve found assumed you had OpenCSV installed somewhere in your server&apos;s classpath.&lt;/p&gt;
&lt;p&gt;Unfortunately, I couldn&apos;t rely on this method for a number of reasons. The primary reason was because I was building this as a plugin  for &lt;a href=&quot;http://www.getmura.com/&quot; target=&quot;_blank&quot;&gt;Mura CMS&lt;/a&gt;. So, if it&apos;s going to be a plugin, I can&apos;t just assume everyone has OpenCSV installed. In addition, Mura offers three different file storage options: 1) locally, 2) Amazon S3 and 3) database. While we could easily use Java&apos;s FileReader method with the first option, the other two would bomb. &lt;/p&gt;
&lt;p&gt;My first stroke of luck was that &lt;a href=&quot;http://compoundtheory.com/&quot; target=&quot;_blank&quot;&gt;Mark Mandel&lt;/a&gt; contributed a nifty little project called &lt;a href=&quot;http://javaloader.riaforge.org/&quot; target=&quot;_blank&quot;&gt;JavaLoader&lt;/a&gt; to the ColdFusion community awhile back. I was also fortunate because Mura offers a way to serve most of its files via the URL. So, using a wee bit of &lt;a href=&quot;http://java.sun.com/docs/books/tutorial/networking/urls/index.html&quot; target=&quot;_blank&quot;&gt;Java&lt;/a&gt; and JavaLoader, I can read in the URL of a CSV file in much the same way as the FileReader method.&lt;/p&gt;
&lt;p&gt;So for completeness, let&apos;s look at both options and then you can decide which one would work best for you.&lt;/p&gt;
&lt;h3&gt;sample.csv&lt;/h3&gt;
&lt;p&gt;You can use any csv file that you want to. This is one I put together for my recent project.&lt;/p&gt;
&lt;code&gt;
LocationName,Lat,Lng,Address,Phone,InfoWindow,Zindex,Icon
Chicago White Sox,,,&quot;333 W 35th St, Chicago, IL 60609&quot;,(312) 674-1000,,1,
Cleveland Indians,,,&quot;2401 Ontario St, Cleveland, OH 44115&quot;,(216) 241-8888,,2,
Detroit Tigers,,,&quot;2100 Woodward Ave, Detroit, MI 48201&quot;,(313) 962-4000,,3,
Kansas City Royals,,,&quot;1 Royal Way, Kansas City, MO 64129&quot;,(816) 921-8000,,4,
Minnesota Twins,,,&quot;351-413 5th Ave N, Minneapolis, MN 55401&quot;,(612) 659-3400,,5,
&lt;/code&gt;

&lt;h3&gt;Parsing CSV With FileReader&lt;/h3&gt;
&lt;code&gt;
&lt;cfscript&gt;
	csvFile = ExpandPath(&quot;/sample.csv&quot;);
	csvData = [];

	// FileReader
	fileReader = createobject(&quot;java&quot;,&quot;java.io.FileReader&quot;);
	fileReader.init(csvFile);

	// use JavaLoader to load OpenCSV
	paths = [ExpandPath(&quot;/opencsv-2.2/deploy/opencsv-2.2.jar&quot;)];
	loader = CreateObject(&quot;component&quot;, &quot;javaloader.JavaLoader&quot;).init(paths);

	csvReader = loader.create(&quot;au.com.bytecode.opencsv.CSVReader&quot;);
	csvReader.init(fileReader);
	csvData = csvReader.readAll();

	// release system resources
	csvReader.close();
	fileReader.close();
&lt;/cfscript&gt;
&lt;cfdump var=&quot;#csvData#&quot; /&gt;
&lt;/code&gt;

&lt;h3&gt;Parsing CSV With URL and InputStreamReader&lt;/h3&gt;
&lt;code&gt;
&lt;cfscript&gt;
	csvUrl = &quot;http://yourdomain.com/sample.csv&quot;;
	csvData = [];

	// InputStreamReader
	streamUrl = CreateObject(&quot;java&quot;,&quot;java.net.URL&quot;).init(csvUrl);
	streamReader = CreateObject(&quot;java&quot;,&quot;java.io.InputStreamReader&quot;).init(streamUrl.openStream());

	// use JavaLoader to load OpenCSV
	paths = [ExpandPath(&quot;/opencsv-2.2/deploy/opencsv-2.2.jar&quot;)];
	loader = CreateObject(&quot;component&quot;, &quot;javaloader.JavaLoader&quot;).init(paths);

	csvReader = loader.create(&quot;au.com.bytecode.opencsv.CSVReader&quot;);
	csvReader.init(streamReader);
	csvData = csvReader.readAll();

	// release system resources
	csvReader.close();
	streamReader.close();
&lt;/cfscript&gt;
&lt;cfdump var=&quot;#csvData#&quot; /&gt;
&lt;/code&gt;
&lt;h3&gt;CFDump Result&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;http://www.stephenwithington.com/blog/images/blog/uploadimages/csv-array.gif&quot; alt=&quot;&quot; border=&quot;0&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I&apos;ve only scratched the surface of what &lt;a href=&quot;http://opencsv.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;OpenCSV&lt;/a&gt; can do for you by the way ... I&apos;ll leave it up to you on how to &lt;em&gt;write CSV files&lt;/em&gt; and even &lt;em&gt;dump out SQL tables to CSV&lt;/em&gt; with OpenCSV. It&apos;s pretty cool stuff!&lt;/p&gt;
&lt;p&gt;Peace.&lt;/p&gt;
				
				</description>
						
				
				<category>Java</category>				
				
				<category>ColdFusion</category>				
				
				<category>Mura CMS</category>				
				
				<pubDate>Fri, 21 May 2010 09:12:00 -0700</pubDate>
				<guid>http://www.stephenwithington.com/blog/index.cfm/2010/5/21/Using-ColdFusion-to-Parse-CSV-via-JavaLoader-and-OpenCSV</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>I&apos;ve Decided To (try to) Learn Java</title>
				<link>http://www.stephenwithington.com/blog/index.cfm/2008/12/27/Ive-Decided-To-try-to-Learn-Java</link>
				<description>
				
				&lt;a href=&quot;http://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://www.stephenwithington.com/blog/images//blog/uploadimages/headfirst_java.jpg&quot; alt=&quot;Head First Java&quot; width=&quot;250&quot; height=&quot;269&quot; hspace=&quot;5&quot; vspace=&quot;5&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
&lt;p&gt;As the new year approaches, I&apos;m adding &amp;quot;Learn Java&amp;quot; to my personal list of things to do in 2009. I&apos;ve been wanting to pick up some Java skills for awhile now and never really set it as a priority. Don&apos;t worry, I have no plans to abandon ColdFusion. Quite the contrary really.&lt;/p&gt;
&lt;p&gt;In my school days, I was required to learn a foreign language.  Victims of &amp;quot;location&amp;quot; and &amp;quot;school budgets,&amp;quot; each grade school within my childhood hometown of Akron, Ohio offered one foreign language option and mine happened to be Spanish. (Friends at other schools were able to learn French, or even German.) Eventually, in high school, Latin was also offered as a foreign language option.  To my excitement, I took both Latin and Spanish. In the end, I truly believe Latin helped me in not only my Spanish, but also my English! (Which some of my readers might take argument with, to be sure.)  Anyway, as it turned out, Latin was/is the basis of approximately 60% of the English language. In addition, Spanish, French, and many other languages are also based on Latin in some form or another, so it&apos;s no wonder that picking up Latin skills could in turn help one in other languages as well.&lt;/p&gt;
&lt;p&gt;As most users of ColdFusion know, Java (or J2EE) is the underlying engine that drives ColdFusion. So in much the same way that I felt Latin helped me in my English and Spanish, I&apos;m hoping Java will also help me in not only my ColdFusion programming, but in other areas as well (object oriented code, etc.).&lt;/p&gt;
&lt;p&gt;I understand that learning a language is an ongoing process and never really &amp;quot;ends.&amp;quot;  Heck, I&apos;m still learning ColdFusion even though I&apos;ve been using it since CF5. I also understand that I&apos;ll probably never really achieve &amp;quot;greatness&amp;quot; in Java considering the fact that I personally know of people that have spent their full four years in college learning this extremely complex language.&lt;/p&gt;
&lt;p&gt;After asking and searching around for a resource to help me in my quest for Java knowledge, I&apos;ve decided on the book &lt;a href=&quot;http://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208&quot; target=&quot;_blank&quot;&gt;&amp;quot;Head First Java, 2nd Edition&amp;quot; by Kathy Sierra and Bert Bates published by O&apos;Reilly&lt;/a&gt;. My book arrived just in time for Christmas and after reading the introduction and flipping around, I can say that I&apos;m truly excited to dive right in. I&apos;m just hoping I&apos;ll be able to swim the Java waters.&lt;p&gt;
				
				</description>
						
				
				<category>Java</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Sat, 27 Dec 2008 08:15:00 -0700</pubDate>
				<guid>http://www.stephenwithington.com/blog/index.cfm/2008/12/27/Ive-Decided-To-try-to-Learn-Java</guid>
				
			</item>
			
		 	
			</channel></rss>