Subscribe via RSS

Announcing FlatPack 3.2 | Java Delimited / Fixed File API

ObjectLab and Paul Zepernick (me) are proud to announce Flatpack 3.2. Flatpack serves as a Java tool box for writing and reading fixed width and delimited files. It is a very mature API that has been in existence since 2005.

FlatPack is currently used in the Apache Camel project and Apache ActiveMQ just to name a couple.

For those not familiar with FlatPack, I have provided a couple quick examples below. Column names in the flat files can be bound via a header record in the file, or through an XML mapping.

Example of reading a delimited file

    	Parser parser = DefaultParserFactory.getInstance().newDelimitedParser(
                new FileReader("DataFile.txt"),  //txt file or String to parse. Can Take any Reader
                ',', //delimiter
                '"'); //text qualifier

        //obtain DataSet
        DataSet ds = parser.parse();

        while (ds.next()){ //loop through file
            ds.getString("mycolumnName");
        }


Example of reading a fixed width file

	    //Obtain the proper parser for your needs
        Parser parser = DefaultParserFactory.getInstance().newFixedLengthParser(
        		new FileReader("map.fpmap.xml"), //fixed with column map
                new FileReader("DataFile.txt"));  //txt file or String to parse.  Can take any Reader

        //obtain DataSet
        DataSet ds = parser.parse();

        while (ds.next()){ //loop through file
            ds.getString("mycolumnName");
        }

Please check out the FlatPack website for more examples and complete documentation, or download now from Sourceforge.

Problems Executing Java From Cron

Today I searched on a path problem when executing a Java program from Cron. The sh script I was executing ran fine when executing in the shell, but hibernate was failing its startup. It turns out that it was not using the correct version of Java. The path export that normally fires when a user shells in was not present when Cron fired the job.

The solution: export the path and append the path to the correct Java version in the shell script.

export PATH=/jdk1.6.0_16/bin:$PATH

Only took about 30 minutes to figure that out…uggg