├── src └── site │ ├── resources │ ├── images │ │ ├── h3_white.png │ │ ├── sonar_logo.png │ │ ├── appendium_logo.jpg │ │ ├── objectlab_logo.jpg │ │ └── banner_background.jpg │ ├── documentation │ │ ├── flatpack-manual.doc │ │ └── flatpack-manual.pdf │ ├── css │ │ └── site.css │ ├── press │ │ ├── press-release-2.3.0.txt │ │ ├── press-release-3.0.0.txt │ │ └── press-release-3.1.0.txt │ └── style │ │ └── maven-objectlabkit.css │ ├── xdoc │ ├── documentation │ │ ├── flatpack-manual.doc │ │ └── flatpack-manual.pdf │ ├── code-metrics.xml │ ├── press │ │ └── index.xml │ ├── history.xml │ └── parsing.xml │ ├── pzfilereader.dtd │ ├── flatpack.dtd │ ├── news.rss │ └── site.xml ├── flatpack └── src │ ├── site │ ├── resources │ │ ├── images │ │ │ ├── h3_white.png │ │ │ ├── appendium_logo.jpg │ │ │ ├── objectlab_logo.jpg │ │ │ └── banner_background.jpg │ │ └── css │ │ │ └── site.css │ ├── xdoc │ │ ├── index.xml │ │ └── code-metrics.xml │ ├── site.xml │ └── style │ │ └── maven-objectlabkit.css │ ├── test │ ├── java │ │ └── net │ │ │ └── sf │ │ │ └── flatpack │ │ │ ├── delim │ │ │ ├── tab │ │ │ │ ├── PEOPLE-TabDelimitedWithQualifier.txt │ │ │ │ ├── TabDelimitedTest.java │ │ │ │ └── TabDelimited.java │ │ │ └── pipe │ │ │ │ └── PipeParserTest.java │ │ │ ├── writer │ │ │ ├── Rfc4180TestCase.java │ │ │ ├── RoundTripTestCase.java │ │ │ ├── AllTests.java │ │ │ ├── PZWriterTestCase.java │ │ │ ├── MultiLineTest.java │ │ │ └── DoubleQualifierWriteReadTest.java │ │ │ ├── columninfile │ │ │ ├── PEOPLE-CommaDelimitedWithQualifier.txt │ │ │ ├── DelimitedColumnNamesInFileTest.java │ │ │ └── DelimitedColumnNamesInFile.java │ │ │ ├── brparse │ │ │ ├── BuffReaderDataSetTest.java │ │ │ ├── BuffReaderFixedParserTest.java │ │ │ └── BuffReaderDelimParserTest.java │ │ │ ├── utilities │ │ │ └── UnitTestUtils.java │ │ │ ├── AllJunitTests.java │ │ │ ├── StreamingTest.java │ │ │ ├── RecordTest.java │ │ │ └── parserutils │ │ │ ├── FixedWidthParserUtilsTest.java │ │ │ └── ParserUtilsLTrimTest.java │ └── resources │ │ ├── log4j.properties │ │ ├── FixedLength.pzmap.xml │ │ ├── BrokenMapping.pzmap.xml │ │ ├── DelimitedWithHeader.pzmap.xml │ │ └── test-complex-fixed.xml │ └── main │ └── java │ ├── fpconvert.properties │ └── net │ └── sf │ └── flatpack │ ├── writer │ ├── WriterFactory.java │ ├── Writer.java │ ├── package.html │ ├── FixedWriterFactory.java │ ├── AbstractWriterFactory.java │ ├── WriterOptions.java │ └── AbstractWriter.java │ ├── util │ ├── FPInvalidUsageException.java │ ├── FPException.java │ ├── package.html │ ├── FPStringUtils.java │ ├── FPConstants.java │ └── FlatpackWriterUtil.java │ ├── xml │ ├── flatpack.dtd │ ├── package.html │ ├── ResolveLocalDTD.java │ └── MetaData.java │ ├── brparse │ ├── InterfaceBuffReaderParse.java │ ├── package.html │ ├── DBBuffReaderFixedParser.java │ └── DBBuffReaderDelimParser.java │ ├── converter │ ├── ConvertBigDecimal.java │ ├── package.html │ ├── Converter.java │ ├── ConvertDouble.java │ ├── ConvertInteger.java │ └── FPConvertException.java │ ├── StreamingRecord.java │ ├── ordering │ └── package.html │ ├── RecordDataSet.java │ ├── package.html │ ├── structure │ └── package.html │ ├── CsvParserFactory.java │ ├── InitialisationException.java │ └── StreamingDataSet.java ├── flatpack-excel └── src │ └── site │ ├── resources │ ├── images │ │ ├── h3_white.png │ │ ├── appendium_logo.jpg │ │ ├── objectlab_logo.jpg │ │ └── banner_background.jpg │ └── css │ │ └── site.css │ ├── xdoc │ ├── index.xml │ └── code-metrics.xml │ ├── site.xml │ └── style │ └── maven-objectlabkit.css ├── flatpack-samples └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── sf │ │ │ └── flatpack │ │ │ └── examples │ │ │ ├── largedataset │ │ │ ├── largecsvperformancetest │ │ │ │ └── settings.properties │ │ │ ├── fixedlengthdynamiccolumns │ │ │ │ └── LargeFixedLengthWithPZMap.java │ │ │ └── delimiteddynamiccolumns │ │ │ │ └── LargeDelimitedWithPZMap.java │ │ │ ├── jsptableexample │ │ │ ├── pzfilereaderwebsamples │ │ │ │ ├── PEOPLE.txt │ │ │ │ ├── WEB-INF │ │ │ │ │ └── web.xml │ │ │ │ ├── PEOPLE.pzmap.xml │ │ │ │ └── index.jsp │ │ │ └── readme.txt │ │ │ ├── csvperformancetest │ │ │ └── settings.properties │ │ │ ├── fixedlengthdynamiccolumns │ │ │ └── FixedLengthWithPZMap.java │ │ │ ├── multilinedelimitedrecord │ │ │ └── DelimitedMultiLine.java │ │ │ ├── numericsanddates │ │ │ └── NumericsAndDates.java │ │ │ ├── lowlevelparse │ │ │ └── LowLevelParse.java │ │ │ ├── delimitedcolumnnamesinfile │ │ │ └── DelimitedColumnNamesInFile.java │ │ │ ├── exporttoexcel │ │ │ └── DelimitedFileExportToExcel.java │ │ │ ├── createsamplecsv │ │ │ └── CSVTestFileCreator.java │ │ │ ├── csvheaderandtrailer │ │ │ └── CSVHeaderAndTrailer.java │ │ │ ├── fixedlengthheaderandtrailer │ │ │ └── FixedLengthHeaderAndTrailer.java │ │ │ └── delimiteddynamiccolumnswitherrors │ │ │ └── DelimitedWithPZMapErrors.java │ └── script │ │ ├── INVENTORY-CommaDelimitedWithQualifier.txt │ │ ├── INVENTORY-Delimited.pzmap.xml │ │ ├── PEOPLE-Delimited.pzmap.xml │ │ ├── PEOPLE-FixedLength.pzmap.xml │ │ ├── PEOPLE-CommaDelimitedWithQualifier.txt │ │ ├── run-examples.bat │ │ ├── PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailer.txt │ │ ├── PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailerRecError.txt │ │ ├── PEOPLE-CommaDelimitedWithQualifierMultiLine.txt │ │ ├── PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml │ │ ├── PEOPLE-FixedLengthWithHeaderTrailer.pzmap.xml │ │ ├── PEOPLE-FixedLength.txt │ │ └── PEOPLE-FixedLengthWithHeaderTrailer.txt │ └── site │ ├── resources │ ├── images │ │ ├── h3_white.png │ │ ├── appendium_logo.jpg │ │ ├── objectlab_logo.jpg │ │ └── banner_background.jpg │ └── css │ │ └── site.css │ ├── site.xml │ └── style │ └── maven-objectlabkit.css ├── SECURITY.md ├── .travis.yml ├── .gitignore ├── travis └── addServer.py ├── README.md └── .github └── workflows └── codeql-analysis.yml /src/site/resources/images/h3_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/images/h3_white.png -------------------------------------------------------------------------------- /src/site/resources/images/sonar_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/images/sonar_logo.png -------------------------------------------------------------------------------- /src/site/resources/images/appendium_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/images/appendium_logo.jpg -------------------------------------------------------------------------------- /src/site/resources/images/objectlab_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/images/objectlab_logo.jpg -------------------------------------------------------------------------------- /flatpack/src/site/resources/images/h3_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack/src/site/resources/images/h3_white.png -------------------------------------------------------------------------------- /src/site/resources/images/banner_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/images/banner_background.jpg -------------------------------------------------------------------------------- /src/site/xdoc/documentation/flatpack-manual.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/xdoc/documentation/flatpack-manual.doc -------------------------------------------------------------------------------- /src/site/xdoc/documentation/flatpack-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/xdoc/documentation/flatpack-manual.pdf -------------------------------------------------------------------------------- /src/site/resources/documentation/flatpack-manual.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/documentation/flatpack-manual.doc -------------------------------------------------------------------------------- /src/site/resources/documentation/flatpack-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/src/site/resources/documentation/flatpack-manual.pdf -------------------------------------------------------------------------------- /flatpack-excel/src/site/resources/images/h3_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-excel/src/site/resources/images/h3_white.png -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/largedataset/largecsvperformancetest/settings.properties: -------------------------------------------------------------------------------- 1 | #csv file to read in 2 | csvFile=SampleCSV.csv -------------------------------------------------------------------------------- /flatpack/src/site/resources/images/appendium_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack/src/site/resources/images/appendium_logo.jpg -------------------------------------------------------------------------------- /flatpack/src/site/resources/images/objectlab_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack/src/site/resources/images/objectlab_logo.jpg -------------------------------------------------------------------------------- /flatpack-samples/src/site/resources/images/h3_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-samples/src/site/resources/images/h3_white.png -------------------------------------------------------------------------------- /flatpack/src/site/resources/images/banner_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack/src/site/resources/images/banner_background.jpg -------------------------------------------------------------------------------- /flatpack-excel/src/site/resources/images/appendium_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-excel/src/site/resources/images/appendium_logo.jpg -------------------------------------------------------------------------------- /flatpack-excel/src/site/resources/images/objectlab_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-excel/src/site/resources/images/objectlab_logo.jpg -------------------------------------------------------------------------------- /flatpack-excel/src/site/resources/images/banner_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-excel/src/site/resources/images/banner_background.jpg -------------------------------------------------------------------------------- /flatpack-samples/src/site/resources/images/appendium_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-samples/src/site/resources/images/appendium_logo.jpg -------------------------------------------------------------------------------- /flatpack-samples/src/site/resources/images/objectlab_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-samples/src/site/resources/images/objectlab_logo.jpg -------------------------------------------------------------------------------- /flatpack-samples/src/site/resources/images/banner_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Appendium/flatpack/HEAD/flatpack-samples/src/site/resources/images/banner_background.jpg -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt: -------------------------------------------------------------------------------- 1 | COL1 COL2 COL3 COL4 COL5 2 | "TEST1" TEST2 TEST3 TEST4 TEST5 3 | TEST1 TEST2 TEST3 TEST4 TEST5 4 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/Rfc4180TestCase.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public abstract class Rfc4180TestCase extends TestCase { 6 | } 7 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | All versions. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | Please create an Issue. A Patch would of course be appreciated. Many thanks 10 | -------------------------------------------------------------------------------- /flatpack/src/main/java/fpconvert.properties: -------------------------------------------------------------------------------- 1 | java.math.BigDecimal=net.sf.flatpack.converter.ConvertBigDecimal 2 | java.lang.Double=net.sf.flatpack.converter.ConvertDouble 3 | java.lang.Integer=net.sf.flatpack.converter.ConvertInteger -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/jsptableexample/pzfilereaderwebsamples/PEOPLE.txt: -------------------------------------------------------------------------------- 1 | JOHN,DOE,1234 CIRCLE CT,ELYRIA,OH,44035 2 | JIMMY,SMITH,180 SOME ST,AVON,OH,44011 3 | JANE,DOE,111 MILKY WY,AMHERST,OH,44001 4 | FRED,FLINTSTONE,123 ROCKY WY,BEDROCK,AZ,12345 5 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/INVENTORY-CommaDelimitedWithQualifier.txt: -------------------------------------------------------------------------------- 1 | "ITEM_DESC","IN_STOCK","PRICE","LAST_RECV_DT" 2 | "SOME VALVE","2","5.00","20050101" 3 | "AN ENGINE","100","1000.00","20040601" 4 | "A BELT","45",".50","20030101" 5 | "A BOLT","1000","2.75","20050101" 6 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/INVENTORY-Delimited.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/csvperformancetest/settings.properties: -------------------------------------------------------------------------------- 1 | #when set to true, the date from the file will be displayed to the screen 2 | #otherwise, the parse will be performed and show the time it took to parse 3 | verbose=false 4 | #csv file to read in 5 | csvFile=SampleCSV.csv -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/WriterFactory.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 7 | * @author Dirk Holmes and Holger Holger Hoffstatte 8 | */ 9 | public interface WriterFactory { 10 | Writer createWriter(java.io.Writer out) throws IOException; 11 | } 12 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-Delimited.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /flatpack/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | 2 | # default properties to initialise log4j 3 | log4j.rootLogger=WARN, A1 4 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 5 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.A1.layout.ConversionPattern=[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n 7 | 8 | # settings for specific packages 9 | #log4j.logger.org.mule=WARN 10 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/jsptableexample/pzfilereaderwebsamples/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | FlatPackSamples 4 | 5 | 6 | index.jsp 7 | 8 | 9 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-FixedLength.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/RoundTripTestCase.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import junit.framework.TestCase; 4 | 5 | /** 6 | * 7 | * @author Dirk Holmes and Holger Holger Hoffstatte 8 | */ 9 | public class RoundTripTestCase extends TestCase { 10 | public void testDummy() { 11 | // TODO DO: write out fixed and delimited files and parse them via 12 | // FlatPack 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/jsptableexample/pzfilereaderwebsamples/PEOPLE.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/FPInvalidUsageException.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.util; 2 | 3 | /** 4 | * Thrown when using a parsing option inappropriately 5 | * 6 | * @author Paul Zepernick 7 | */ 8 | public class FPInvalidUsageException extends RuntimeException { 9 | private static final long serialVersionUID = 1L; 10 | 11 | public FPInvalidUsageException(final String msg) { 12 | super(msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/site/pzfilereader.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-CommaDelimitedWithQualifier.txt: -------------------------------------------------------------------------------- 1 | "FIRSTNAME","LASTNAME","ADDRESS","CITY","STATE","ZIP" 2 | "JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035" 3 | "JIMMY","ZNAME","180 SOME ST","AVON","OH","44011" 4 | "JANE","ANAME","111 MILKY WY","AVON","OH","44001" 5 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 6 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 7 | "FRED","ZNAME","Text Qualifier " and seperator, in string","ELYRIA","OH","" 8 | -------------------------------------------------------------------------------- /flatpack/src/test/resources/FixedLength.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /flatpack/src/test/resources/BrokenMapping.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt: -------------------------------------------------------------------------------- 1 | "FIRSTNAME","LASTNAME","ADDRESS","CITY","STATE","ZIP" 2 | "JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035" 3 | "JIMMY","ZNAME","180 SOME ST","AVON","OH","44011" 4 | "JANE","ANAME","111 MILKY WY","AVON","OH","44001" 5 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 6 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 7 | "FRED","ZNAME","Text Qualifier "" and separator, in string","ELYRIA","OH","" 8 | -------------------------------------------------------------------------------- /src/site/flatpack.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 12 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/xml/flatpack.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/run-examples.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | title RunExamples 3 | 4 | set CLASSPATH=%CLASSPATH%;./flatpack-@JARFILE@.jar 5 | set CLASSPATH=%CLASSPATH%;./@JARFILEEXAMPLES@ 6 | set CLASSPATH=%CLASSPATH%;./jdom.jar 7 | set CLASSPATH=%CLASSPATH%;./jxl.jar 8 | set CLASSPATH=%CLASSPATH%;./slf4j-api-1.1.0-RC1.jar 9 | set CLASSPATH=%CLASSPATH%;./slf4j-simple-1.1.0-RC1.jar 10 | set CLASSPATH=%CLASSPATH%;. 11 | 12 | echo %CLASSPATH% 13 | 14 | "%JAVA_HOME%\bin\java" -Xmx512m -Xms512m net.sf.flatpack.examples.Examples 15 | 16 | pause -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailer.txt: -------------------------------------------------------------------------------- 1 | "FIRSTNAME","LASTNAME","ADDRESS","CITY","STATE","ZIP" 2 | "H","Some Header Data Here" 3 | "JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035" 4 | "JIMMY","ZNAME","180 SOME ST","AVON","OH","44011" 5 | "JANE","ANAME","111 MILKY WY","AVON","OH","44001" 6 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 7 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 8 | "FRED","ZNAME","Text Qualifier " and seperator, in string","ELYRIA","OH","" 9 | "T","Some Trailer Data Here" 10 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailerRecError.txt: -------------------------------------------------------------------------------- 1 | "FIRSTNAME","LASTNAME","ADDRESS","CITY","STATE","ZIP" 2 | "H","Some Header Data Here" 3 | "JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035" 4 | "JIMMY","ZNAME","180 SOME ST","AVON","OH","44011" 5 | "JANE","ANAME","111 MILKY WY","AVON","OH","44001" 6 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345","Extra Element To Produce An Error" 7 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345" 8 | "FRED","ZNAME","Text Qualifier " and seperator, in string","ELYRIA","OH","" 9 | "T","Some Trailer Data Here" 10 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/AllTests.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestSuite; 5 | 6 | /** 7 | * 8 | * @author Dirk Holmes and Holger Holger Hoffstatte 9 | */ 10 | public class AllTests { 11 | 12 | public static Test suite() { 13 | final TestSuite suite = new TestSuite("Test for net.sf.flatpack.writer"); 14 | // $JUnit-BEGIN$ 15 | suite.addTestSuite(DelimiterWriterTest.class); 16 | suite.addTestSuite(FixedLengthWriterTest.class); 17 | // $JUnit-END$ 18 | return suite; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/Writer.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 7 | * @author Dirk Holmes and Holger Holger Hoffstatte 8 | */ 9 | public interface Writer extends AutoCloseable { 10 | /** Export header */ 11 | Writer printHeader() throws IOException; 12 | 13 | /** Export footer */ 14 | Writer printFooter() throws IOException; 15 | 16 | Writer addRecordEntry(String columnName, Object value); 17 | 18 | Writer nextRecord() throws IOException; 19 | 20 | Writer flush() throws IOException; 21 | 22 | @Override 23 | void close() throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /src/site/news.rss: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PZFileReader News 6 | http://pzfilereader.sourceforge.net 7 | PZFileReader News 8 | en-us 9 | Copyright 2007 PZFileReader Sourceforge Development Group & ObjectLab 10 | 11 | 12 | PZFileReader 3.0.0 is released. 13 | This is a major release with new interfaces and massive performance gains (orders of magnitude).

15 | ]]>
16 |
17 | 18 |
19 |
-------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/jsptableexample/readme.txt: -------------------------------------------------------------------------------- 1 | This example has been tested under Tomcat 5. 2 | 3 | 1. Paste the PZFileReaderWebSamples into your 4 | "Tomcat Install Dir"/webapps 5 | 2. Paste Flatpack*.jar into the lib folder along with any dependencies 6 | 3. Start tomcat 7 | 4. Point your browser to http://localhost:8080/PZFileReaderWebSamples 8 | 9 | 10 | This should work under most java servers. Simply paste the PZFileReaderWebSamples 11 | folder into the appropriate deployment directory for your server. 12 | 13 | 14 | 15 | - Provides a jsp which spits the CSV file out to a html table. The columns in the table can then be clicked on to 16 | resort. -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/brparse/InterfaceBuffReaderParse.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import net.sf.flatpack.DefaultDataSet; 4 | import net.sf.flatpack.structure.Row; 5 | 6 | /** 7 | * All buffered reader parsers should implement this interface and provide 8 | * an implementation for the buildRow 9 | * 10 | * @author Paul Zepernick 11 | */ 12 | public interface InterfaceBuffReaderParse extends AutoCloseable { 13 | 14 | /** 15 | * Builds a row into the DataSet using the current record from the File 16 | * 17 | * @param ds 18 | * @return Row object 19 | */ 20 | public Row buildRow(final DefaultDataSet ds); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-CommaDelimitedWithQualifierMultiLine.txt: -------------------------------------------------------------------------------- 1 | "FIRSTNAME","LASTNAME","ADDRESS","CITY","STATE","ZIP","FREE FORM COMMENTS" 2 | "JOHN","ANAME","1234 CIRCLE CT","ELYRIA","OH","44035", "here is a comment" 3 | "JIMMY","ZNAME","180 SOME ST","AVON","OH","44011","here is a 4 | comment with some line breaks 5 | in it" 6 | "JANE","ANAME","111 MILKY WY 7 | Lets See How It Does 8 | With Some Breaks In The Address 9 | Field","AVON","OH","44001", "comments here" 10 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345","more comments" 11 | "FRED","ZNAME","123 ROCKY WY","ELYRIA","OH","12345","" 12 | "FRED","ZNAME","Text Qualifier " and seperator, 13 | in string break 14 | break 15 | break","ELYRIA","OH","","last comment :)" 16 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/ConvertBigDecimal.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.converter; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import net.sf.flatpack.util.ParserUtils; 6 | 7 | /** 8 | * Returns a BigDecimal 9 | * Non numeric chars are removed from the string 10 | * before converting 11 | * 12 | * @author Paul Zepernick 13 | */ 14 | public class ConvertBigDecimal implements Converter { 15 | /* 16 | * (non-Javadoc) 17 | * 18 | * @see net.sf.flatpack.converter#convertValue(java.lang.String) 19 | */ 20 | @Override 21 | public Object convertValue(final String valueToConvert) { 22 | return new BigDecimal(ParserUtils.stripNonDoubleChars(valueToConvert)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /flatpack/src/test/resources/DelimitedWithHeader.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-FixedLengthWithHeaderTrailer.pzmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/FPException.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.util; 2 | 3 | /** 4 | * Generic exception for FlatPack 5 | * 6 | * @author Paul Zepernick 7 | */ 8 | public class FPException extends RuntimeException { 9 | private static final long serialVersionUID = -4269317129024968528L; 10 | 11 | public FPException() { 12 | } 13 | 14 | /** 15 | * @param message the exception message 16 | */ 17 | public FPException(final String message) { 18 | super(message); 19 | } 20 | 21 | /** 22 | * @param cause the original exception 23 | */ 24 | public FPException(final Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public FPException(final String message, final Throwable cause) { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | #banner { 2 | background: transparent url(../images/banner_background.jpg) repeat scroll 0 0; 3 | height: 80px; 4 | } 5 | 6 | h2 { 7 | color: #2872B4; 8 | } 9 | 10 | h3 { 11 | color: #2872B4; 12 | background-color: #FFFFFF; 13 | background-image: url(../images/h3_white.png); 14 | border-bottom: 1px solid #CCCCCC; 15 | } 16 | 17 | h4 { 18 | color: #2872B4; 19 | font-size: 12px; 20 | font-weight: bold; 21 | } 22 | 23 | #navcolumn h5 { 24 | color: #2872B4; 25 | border-bottom: 1px solid #CCCCCC; 26 | } 27 | 28 | #footer { 29 | border-top: 1px solid #2872B4; 30 | } 31 | 32 | #sonar { 33 | padding: 20px 20px 20px 20px; 34 | text-align: left; 35 | } 36 | 37 | #ohloh { 38 | } 39 | 40 | #cocomo { 41 | float:left; 42 | margin:10px 0 0 10px; 43 | } 44 | 45 | #factoids { 46 | margin:0 0 10px 320px; 47 | } -------------------------------------------------------------------------------- /flatpack/src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | #banner { 2 | background: transparent url(../images/banner_background.jpg) repeat scroll 0 0; 3 | height: 80px; 4 | } 5 | 6 | h2 { 7 | color: #2872B4; 8 | } 9 | 10 | h3 { 11 | color: #2872B4; 12 | background-color: #FFFFFF; 13 | background-image: url(../images/h3_white.png); 14 | border-bottom: 1px solid #CCCCCC; 15 | } 16 | 17 | h4 { 18 | color: #2872B4; 19 | font-size: 12px; 20 | font-weight: bold; 21 | } 22 | 23 | #navcolumn h5 { 24 | color: #2872B4; 25 | border-bottom: 1px solid #CCCCCC; 26 | } 27 | 28 | #footer { 29 | border-top: 1px solid #2872B4; 30 | } 31 | 32 | #sonar { 33 | padding: 20px 20px 20px 20px; 34 | text-align: left; 35 | } 36 | 37 | #ohloh { 38 | } 39 | 40 | #cocomo { 41 | float:left; 42 | margin:10px 0 0 10px; 43 | } 44 | 45 | #factoids { 46 | margin:0 0 10px 320px; 47 | } -------------------------------------------------------------------------------- /flatpack-excel/src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | #banner { 2 | background: transparent url(../images/banner_background.jpg) repeat scroll 0 0; 3 | height: 80px; 4 | } 5 | 6 | h2 { 7 | color: #2872B4; 8 | } 9 | 10 | h3 { 11 | color: #2872B4; 12 | background-color: #FFFFFF; 13 | background-image: url(../images/h3_white.png); 14 | border-bottom: 1px solid #CCCCCC; 15 | } 16 | 17 | h4 { 18 | color: #2872B4; 19 | font-size: 12px; 20 | font-weight: bold; 21 | } 22 | 23 | #navcolumn h5 { 24 | color: #2872B4; 25 | border-bottom: 1px solid #CCCCCC; 26 | } 27 | 28 | #footer { 29 | border-top: 1px solid #2872B4; 30 | } 31 | 32 | #sonar { 33 | padding: 20px 20px 20px 20px; 34 | text-align: left; 35 | } 36 | 37 | #ohloh { 38 | } 39 | 40 | #cocomo { 41 | float:left; 42 | margin:10px 0 0 10px; 43 | } 44 | 45 | #factoids { 46 | margin:0 0 10px 320px; 47 | } -------------------------------------------------------------------------------- /flatpack-samples/src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | #banner { 2 | background: transparent url(../images/banner_background.jpg) repeat scroll 0 0; 3 | height: 80px; 4 | } 5 | 6 | h2 { 7 | color: #2872B4; 8 | } 9 | 10 | h3 { 11 | color: #2872B4; 12 | background-color: #FFFFFF; 13 | background-image: url(../images/h3_white.png); 14 | border-bottom: 1px solid #CCCCCC; 15 | } 16 | 17 | h4 { 18 | color: #2872B4; 19 | font-size: 12px; 20 | font-weight: bold; 21 | } 22 | 23 | #navcolumn h5 { 24 | color: #2872B4; 25 | border-bottom: 1px solid #CCCCCC; 26 | } 27 | 28 | #footer { 29 | border-top: 1px solid #2872B4; 30 | } 31 | 32 | #sonar { 33 | padding: 20px 20px 20px 20px; 34 | text-align: left; 35 | } 36 | 37 | #ohloh { 38 | } 39 | 40 | #cocomo { 41 | float:left; 42 | margin:10px 0 0 10px; 43 | } 44 | 45 | #factoids { 46 | margin:0 0 10px 320px; 47 | } -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/StreamingRecord.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | public class StreamingRecord implements StreamingDataSet { 8 | private final DataSet dataSet; 9 | 10 | public StreamingRecord(final DataSet dataSet) { 11 | super(); 12 | this.dataSet = dataSet; 13 | } 14 | 15 | @Override 16 | public Optional getRecord() { 17 | return dataSet.getRecord(); 18 | } 19 | 20 | @Override 21 | public boolean next() { 22 | return dataSet != null && dataSet.next(); 23 | } 24 | 25 | @Override 26 | public int getErrorCount() { 27 | return dataSet != null ? dataSet.getErrorCount() : 0; 28 | } 29 | 30 | @Override 31 | public List getErrors() { 32 | return dataSet != null ? dataSet.getErrors() : Collections.emptyList(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/xml/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.xml package 5 | 20 | 21 | 22 | Provides classes for handling and parsing of the *.pzmap.xml files. 23 | 24 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/brparse/BuffReaderDataSetTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.io.StringReader; 6 | 7 | import junit.framework.TestCase; 8 | import net.sf.flatpack.CsvParserFactory; 9 | import net.sf.flatpack.DataSet; 10 | import net.sf.flatpack.Parser; 11 | 12 | public class BuffReaderDataSetTest extends TestCase { 13 | private static final String CSV = "col1,col2" + System.getProperty("line.separator") + "val1,val2"; 14 | 15 | public void testCsv() { 16 | final Parser parser = CsvParserFactory.newForwardParser(new StringReader(CSV)); 17 | final DataSet ds = parser.parse(); 18 | assertThat(ds.getErrorCount()).isEqualTo(0); 19 | assertThat(ds.next()).isTrue(); 20 | assertThat(ds.getString("col1")).isEqualToIgnoringCase("val1"); 21 | assertThat(ds.getString("col2")).isEqualToIgnoringCase("val2"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/ordering/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.ordering package 5 | 20 | 21 | 22 | Responsible for all sorting operations performed on a DataSet 23 | 24 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/RecordDataSet.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | /** 7 | * Rather than treating a DataSet as a stateful class whereby we need to extract each column one by 8 | * one, this interface allows you to extract a record at a time. 9 | * @since 3.4 10 | */ 11 | public interface RecordDataSet { 12 | /** 13 | * Returns true if it has one more record. false if not 14 | * 15 | * @return boolean 16 | */ 17 | boolean next(); 18 | 19 | Optional getRecord(); 20 | 21 | /** 22 | * Returns A Collection Of DataErrors that happened during processing 23 | * 24 | * @return Vector 25 | */ 26 | List getErrors(); 27 | 28 | /** 29 | * Returns total number of records which contained a parse error in the 30 | * file. 31 | * 32 | * @return int - Record Error Count 33 | */ 34 | int getErrorCount(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import junit.framework.TestCase; 4 | 5 | /** 6 | * 7 | * @author Dirk Holmes and Holger Holger Hoffstatte 8 | */ 9 | public abstract class PZWriterTestCase extends TestCase { 10 | private final String lineSeparator = System.getProperty("line.separator"); 11 | 12 | protected String joinLines(final String line1, final String line2) { 13 | if (line1 == null) { 14 | throw new IllegalArgumentException("parameter string1 may not be null"); 15 | } 16 | 17 | final StringBuilder result = new StringBuilder(line1); 18 | result.append(lineSeparator); 19 | if (line2 != null) { 20 | result.append(line2); 21 | result.append(lineSeparator); 22 | } 23 | 24 | return result.toString(); 25 | } 26 | 27 | protected String normalizeLineEnding(final String line) { 28 | return this.joinLines(line, null); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/brparse/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.brparse package 5 | 20 | 21 | 22 | Contains parsers which leave an open BufferedReader for file access. The parser 23 | refrain from doing a "pre parse" and reading the file into memory. 24 | 25 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/package.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | net.sf.pzfilereader.ordering package 20 | 21 | Main package of the project, containing the 22 | actual DataSet implementations. Classes also exist which describe the 23 | version number, and the structure of a data error. 24 | 25 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.flatpack.util package 5 | 20 | 21 | 22 | Provides some Writers to export a DataSet to a fixed length or delimited format. Thanks to Dirk and Holger from MuleSource for the 23 | initial contribution. 24 | 25 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/structure/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.ordering package 5 | 20 | 21 | 22 | Contains classes which decribes the structure of the DataSet. 23 | Information is stored on the structure of a Row (record) and 24 | the ColumnMetaData for the columns contained in the Row. 25 | 26 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.converter package 5 | 20 | 21 | 22 | Contains PZConverter implementations for converting reader data into its 23 | appropriate object via the getObject() call on the IDataSet. These converters 24 | are registered via the pzconvert.properties file. 25 | 26 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/FixedWriterFactory.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.IOException; 4 | import java.io.Reader; 5 | import java.util.Map; 6 | 7 | /** 8 | * 9 | * @author Dirk Holmes and Holger Holger Hoffstatte 10 | */ 11 | public class FixedWriterFactory extends AbstractWriterFactory { 12 | public static final char DEFAULT_PADDING_CHARACTER = ' '; 13 | 14 | private final char pad; 15 | 16 | public FixedWriterFactory(final Map mapping) { 17 | super(mapping); 18 | this.pad = DEFAULT_PADDING_CHARACTER; 19 | } 20 | 21 | public FixedWriterFactory(final Reader mappingSrc) throws IOException { 22 | this(mappingSrc, DEFAULT_PADDING_CHARACTER); 23 | } 24 | 25 | public FixedWriterFactory(final Reader mappingSrc, final char fillChar) throws IOException { 26 | super(mappingSrc); 27 | this.pad = fillChar; 28 | } 29 | 30 | @Override 31 | public Writer createWriter(final java.io.Writer output) throws IOException { 32 | return new FixedLengthWriter(this.getColumnMapping(), output, pad); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-FixedLength.txt: -------------------------------------------------------------------------------- 1 | JOHN DOE 1234 CIRCLE CT ELYRIA OH44035 2 | JIMMY SMITH 180 SOME ST AVON OH44011 3 | JANE DOE 111 MILKY WY AMHERST OH44001 4 | FRED FLINTSTONE 123 ROCKY WY BEDROCK AZ12345 5 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/script/PEOPLE-FixedLengthWithHeaderTrailer.txt: -------------------------------------------------------------------------------- 1 | HEADER HeaderDataHere 2 | JOHN DOE 1234 CIRCLE CT ELYRIA OH44035 3 | JIMMY SMITH 180 SOME ST AVON OH44011 4 | JANE DOE 111 MILKY WY AMHERST OH44001 5 | FRED FLINTSTONE 123 ROCKY WY BEDROCK AZ12345 6 | TRAILERFooterDataHere 7 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net.sf.pzfilereader.util package 5 | 20 | 21 | 22 | Provides utility methods that are used to perform parsing and transform DataSets into Excel. 23 |
    24 |
  • Parse Line Of Delimited Text
  • 25 |
  • Check For Multiline Delimted Record
  • 26 |
  • Find Column Postion Based On The Column Name
  • 27 |
  • Various Types Of Left Trims And Padding
  • 28 |
29 | 30 | -------------------------------------------------------------------------------- /flatpack/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Benoit Xhenseval 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |

Check out the JavaDoc here

24 |

Also look at the Project Reports menu on the left for project specific items, unit tests, QA etc.

25 |
26 | 27 | 28 |
-------------------------------------------------------------------------------- /flatpack-excel/src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Benoit Xhenseval 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |

Check out the JavaDoc here

24 |

Also look at the Project Reports menu on the left for project specific items, unit tests, QA etc.

25 |
26 | 27 | 28 |
29 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/utilities/UnitTestUtils.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.utilities; 2 | 3 | /** 4 | * Static utility methods for Junit tests 5 | * 6 | * @author Paul Zepernick 7 | */ 8 | public class UnitTestUtils { 9 | 10 | /** 11 | * Builds a delimited qualified string containing the elements passed in. 12 | * 13 | * @param elements 14 | * Elements To Include In Delimited String 15 | * @param delimiter 16 | * The delimiter, e.g. a comma 17 | * @param qualifier 18 | * The qualifier, e.g. a double quote 19 | * @return String 20 | */ 21 | public static String buildDelimString(final String[] elements, final char delimiter, final char qualifier) { 22 | final StringBuilder sb = new StringBuilder(); 23 | for (int i = 0; i < elements.length; i++) { 24 | if (i > 0) { 25 | sb.append(delimiter); 26 | } 27 | if (qualifier != 0) { 28 | sb.append(qualifier); 29 | } 30 | sb.append(elements[i]); 31 | if (qualifier != 0) { 32 | sb.append(qualifier); 33 | } 34 | } 35 | return sb.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/CsvParserFactory.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.io.Reader; 4 | 5 | import lombok.experimental.UtilityClass; 6 | import net.sf.flatpack.brparse.BuffReaderParseFactory; 7 | 8 | /** 9 | * Easy way to get a CSV Parser (separator , and qualifier "). 10 | * 11 | */ 12 | @UtilityClass 13 | public final class CsvParserFactory { 14 | /** 15 | * This should be your default mechanism, it does not keep previous records as you stream the results, so 16 | * it is more memory efficient but the downside is that you cannot reset the parsing or restart it. It reads 17 | * a line, parses it and returns a Record or the next entry in the DataSet. 18 | * @param reader the data source 19 | * @return a CSV Parser 20 | */ 21 | public static Parser newForwardParser(Reader reader) { 22 | return BuffReaderParseFactory.getInstance().newDelimitedParser(reader, ',', '"'); 23 | } 24 | 25 | /** 26 | * With this Parser, everything is loaded in memory, you can reset the parsing or restart it, etc. 27 | * @param reader the data source 28 | * @return a CSV Parser 29 | */ 30 | public static Parser newInMemoryParser(Reader reader) { 31 | return DefaultParserFactory.newCsvParser(reader); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /flatpack/src/test/resources/test-complex-fixed.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /flatpack-samples/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | Get FlatPack Java API For Flat Files at SourceForge.net. Fast, secure and Free Open Source software downloads 21 |
22 | 25 | 28 |
29 | 30 |
-------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | install: true 4 | #addons: 5 | # sonarcloud: 6 | # organization: benoitx-github 7 | # token: 8 | # secure: 13b70009cbae7646c3458517212a3ba73faff609 9 | git: 10 | depth: 3 11 | env: 12 | global: 13 | - SONATYPE_USERNAME=benoitx 14 | - secure: MtZwtUKZtF83MDYsKbZeyJn0R9xvSFBA9jJpk1wQXJ/zZCQsNbBJGm8ez8l5x++tGwX5BvbEeH3rqWrul9gNLcNG5PXUnar5rAHUFAHnEr3OuPfKogkOGMXxK0xXWzeKIJx5nDAAPvqlMe7lGOogA60ZFfQM3CdHwbWlNo/xVVI= 15 | - secure: DSPCcO+Ny49IioFE8AHUyAEIVCP+j+5xJSyj3z9TvFfSgvLVrVPbhb62dkvheA0j2gaIOWVqivmqp3ZLzCDavyUZFzKtpp1Jo1SwcrG0kKG2dR/abQ8Vf2ct1n+5l0ebOQlAxVZnJpbAoKNYl3aT7wrOkrVtEAB4dUNaKUDJ7aU= 16 | jdk: 17 | - openjdk8 18 | script: 19 | # mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar 20 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package 21 | cache: 22 | directories: 23 | - "$HOME/.m2/repository" 24 | - "$HOME/.sonar/cache" 25 | notifications: 26 | email: 27 | recipients: 28 | - opensource@appendium.com 29 | on_success: always 30 | on_failure: always 31 | slack: 32 | secure: DTRTtJQpTUX4XkoS8Df2Zi1pcWVLQKIsfMjHmPEv481V3DeBQWJvn7LPWE5YpK/pdD/3LasnASWIGS2ijb9i0bfrwcaH+MWm0vSfg9+5lDhtSlFDM1QXJIhOmjm1bozEYG2lcPZz6u8CSIEBFSATAXZCkxzYAJ5bH5AM1jxJfoI= 33 | after_success: 34 | - '[[ $TRAVIS_BRANCH == "master" ]] && { python travis/addServer.py; mvn clean deploy 35 | --settings ~/.m2/mySettings.xml; };' 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse/development # 2 | ######################## 3 | .settings/ 4 | test-output/ 5 | logs 6 | .springBeans 7 | bin/ 8 | 9 | # Compiled source # 10 | ################### 11 | *.com 12 | *.class 13 | *.dll 14 | *.exe 15 | *.o 16 | *.so 17 | *.classpath 18 | *.project 19 | *.prefs 20 | 21 | target/ 22 | 23 | # Packages # 24 | ############ 25 | # it's better to unpack these files and commit the raw source 26 | # git has its own built in compression methods 27 | *.7z 28 | *.dmg 29 | *.gz 30 | *.iso 31 | *.jar 32 | *.rar 33 | *.tar 34 | *.zip 35 | 36 | # Logs and databases # 37 | ###################### 38 | *.log 39 | *.sqlite 40 | 41 | # OS generated files # 42 | ###################### 43 | .DS_Store 44 | .DS_Store? 45 | ._* 46 | .Spotlight-V100 47 | .Trashes 48 | Icon? 49 | ehthumbs.db 50 | Thumbs.db 51 | *.pid 52 | *.lck 53 | *.swp 54 | 55 | flatpack/.project 56 | 57 | release.properties 58 | *.iml 59 | flatpack/src/main/java/TestLoad.java 60 | flatpack/pom.xml.versionsBackup 61 | flatpack-samples/pom.xml.versionsBackup 62 | pom.xml.versionsBackup 63 | flatpack-excel/pom.xml.next 64 | flatpack-excel/pom.xml.releaseBackup 65 | flatpack-excel/pom.xml.tag 66 | flatpack-samples/pom.xml.next 67 | flatpack-samples/pom.xml.releaseBackup 68 | flatpack-samples/pom.xml.tag 69 | flatpack/pom.xml.next 70 | flatpack/pom.xml.releaseBackup 71 | flatpack/pom.xml.tag 72 | pom.xml.next 73 | pom.xml.releaseBackup 74 | pom.xml.tag 75 | src/notes/settings.xml 76 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/AllJunitTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Feb 27, 2006 3 | */ 4 | package net.sf.flatpack; 5 | 6 | import junit.framework.Test; 7 | import junit.framework.TestSuite; 8 | 9 | /** 10 | * @author zepernick 11 | * 12 | * This class will execute all Junit tests together 13 | */ 14 | public class AllJunitTests { 15 | 16 | public static Test suite() { 17 | final TestSuite suite = new TestSuite("Test For All flatpack Functionality"); 18 | // $JUnit-BEGIN$ 19 | suite.addTest(new TestSuite(net.sf.flatpack.columninfile.DelimitedColumnNamesInFileTest.class)); 20 | suite.addTest(new TestSuite(net.sf.flatpack.delim.tab.TabDelimitedTest.class)); 21 | suite.addTest(new TestSuite(net.sf.flatpack.delim.csv.CsvParserTest.class)); 22 | suite.addTest(new TestSuite(net.sf.flatpack.delim.pipe.PipeParserTest.class)); 23 | suite.addTest(new TestSuite(net.sf.flatpack.delim.tab.TabDelimitedTest.class)); 24 | suite.addTest(new TestSuite(net.sf.flatpack.parserutils.FixedWidthParserUtilsTest.class)); 25 | suite.addTest(new TestSuite(net.sf.flatpack.parserutils.ParserUtilsLTrimTest.class)); 26 | suite.addTest(new TestSuite(net.sf.flatpack.parserutils.ParserUtilsSplitLineTest.class)); 27 | suite.addTest(new TestSuite(net.sf.flatpack.parserutils.ParserUtilsTest.class)); 28 | suite.addTest(new TestSuite(net.sf.flatpack.pzparser.PZParserOptsTest.class)); 29 | // $JUnit-END$ 30 | return suite; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /travis/addServer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | import os 4 | import os.path 5 | import xml.dom.minidom 6 | 7 | if os.environ["TRAVIS_SECURE_ENV_VARS"] == "false": 8 | print "no secure env vars available, skipping deployment" 9 | sys.exit() 10 | 11 | homedir = os.path.expanduser("~") 12 | m2 = xml.dom.minidom.parse(homedir + '/.m2/settings.xml') 13 | settings = m2.getElementsByTagName("settings")[0] 14 | 15 | serversNodes = settings.getElementsByTagName("servers") 16 | if not serversNodes: 17 | serversNode = m2.createElement("servers") 18 | settings.appendChild(serversNode) 19 | else: 20 | serversNode = serversNodes[0] 21 | 22 | sonatypeServerNode = m2.createElement("server") 23 | sonatypeServerId = m2.createElement("id") 24 | sonatypeServerUser = m2.createElement("username") 25 | sonatypeServerPass = m2.createElement("password") 26 | 27 | #idNode = m2.createTextNode("sonatype-nexus-snapshots") 28 | idNode = m2.createTextNode("ossrh") 29 | userNode = m2.createTextNode(os.environ["SONATYPE_USERNAME"]) 30 | passNode = m2.createTextNode(os.environ["SONATYPE_PASSWORD"]) 31 | 32 | sonatypeServerId.appendChild(idNode) 33 | sonatypeServerUser.appendChild(userNode) 34 | sonatypeServerPass.appendChild(passNode) 35 | 36 | sonatypeServerNode.appendChild(sonatypeServerId) 37 | sonatypeServerNode.appendChild(sonatypeServerUser) 38 | sonatypeServerNode.appendChild(sonatypeServerPass) 39 | 40 | serversNode.appendChild(sonatypeServerNode) 41 | 42 | m2Str = m2.toxml() 43 | f = open(homedir + '/.m2/mySettings.xml', 'w') 44 | f.write(m2Str) 45 | f.close() -------------------------------------------------------------------------------- /flatpack/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 | 25 | Get FlatPack Java API For Flat Files at SourceForge.net. Fast, secure and Free Open Source software downloads 29 | 30 |
31 | 33 | 36 |
37 | 38 |
-------------------------------------------------------------------------------- /flatpack-excel/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 | 25 | Get FlatPack Java API For Flat Files at SourceForge.net. Fast, secure and Free Open Source software downloads 29 | 30 |
31 | 33 | 36 |
37 | 38 |
-------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderFixedParser.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.Reader; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | import java.util.List; 8 | 9 | import net.sf.flatpack.InitialisationException; 10 | import net.sf.flatpack.structure.ColumnMetaData; 11 | import net.sf.flatpack.util.ParserUtils; 12 | 13 | public class DBBuffReaderFixedParser extends BuffReaderFixedParser implements InterfaceBuffReaderParse { 14 | private final Connection con; 15 | 16 | public DBBuffReaderFixedParser(final Connection con, final Reader dataSourceReader, final String dataDefinition) { 17 | super(dataSourceReader, dataDefinition); 18 | this.con = con; 19 | } 20 | 21 | @Override 22 | protected void init() { 23 | try { 24 | 25 | final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); 26 | addToMetaData(cmds); 27 | 28 | if (cmds.isEmpty()) { 29 | throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); 30 | } 31 | setInitialised(true); 32 | } catch (final SQLException | FileNotFoundException e) { 33 | throw new InitialisationException(e); 34 | } 35 | } 36 | 37 | protected boolean shouldCreateMDFromFile() { 38 | // The MetaData should always be pulled from the DB for this implementation 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriterFactory.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.IOException; 4 | import java.io.Reader; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import net.sf.flatpack.InitialisationException; 11 | import net.sf.flatpack.util.FPConstants; 12 | import net.sf.flatpack.xml.MapParser; 13 | 14 | /** 15 | * 16 | * @author Dirk Holmes and Holger Holger Hoffstatte 17 | */ 18 | public abstract class AbstractWriterFactory implements WriterFactory { 19 | private Map mapping; 20 | 21 | protected AbstractWriterFactory() { 22 | super(); 23 | 24 | mapping = new HashMap(); 25 | mapping.put(FPConstants.DETAIL_ID, new ArrayList()); 26 | mapping.put(FPConstants.COL_IDX, new HashMap()); 27 | } 28 | 29 | protected AbstractWriterFactory(final Map mapping) { 30 | super(); 31 | this.mapping = mapping; 32 | } 33 | 34 | protected AbstractWriterFactory(final Reader mappingSrc) throws IOException { 35 | this(); 36 | 37 | try { 38 | mapping = MapParser.parse(mappingSrc, null); 39 | } catch (final Exception jde) { 40 | throw new InitialisationException(jde); 41 | } 42 | } 43 | 44 | protected Map getColumnMapping() { 45 | // TODO DO: return deep mutable clone here or better: make the Map a 46 | // first class 47 | // citizen of the library 48 | return Collections.unmodifiableMap(mapping); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://secure.travis-ci.org/Appendium/flatpack.png?branch=master)](http://travis-ci.org/Appendium/flatpack) 2 | [![SonarQube](https://sonarcloud.io/api/project_badges/measure?project=net.sf.flatpack:flatpack-parent&metric=bugs)](https://sonarcloud.io/dashboard/index/net.sf.flatpack:flatpack-parent) 3 | [![Sonar Reliability](https://sonarcloud.io/api/project_badges/measure?project=net.sf.flatpack:flatpack-parent&metric=reliability_rating)](https://sonarcloud.io/dashboard/index/net.sf.flatpack:flatpack-parent) 4 | [![Sonar Security](https://sonarcloud.io/api/project_badges/measure?project=net.sf.flatpack:flatpack-parent&metric=security_rating)](https://sonarcloud.io/dashboard/index/net.sf.flatpack:flatpack-parent) 5 | [![Maven Central Flatpack](https://maven-badges.herokuapp.com/maven-central/net.sf.flatpack/flatpack/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.sf.flatpack/flatpack) 6 | ![GitHub license](https://img.shields.io/github/license/appendium/flatpack.svg?style=flat-square) 7 | 8 | [![Quality Gate](https://sonarcloud.io/api/project_badges/quality_gate?project=net.sf.flatpack:flatpack-parent)](https://sonarcloud.io/dashboard/index/net.sf.flatpack:flatpack-parent) 9 | 10 | 11 | flatpack 12 | ======== 13 | 14 | CSV/Tab Delimited and Fixed Length Parser and Writer 15 | 16 | FlatPack on SourceForge: a Java (1.8+) flat file parser that handles CSV, 17 | fixed length and custom delimiters. It can handle very large files. 18 | 19 | The formats are configured in XML, it is fast and released under Apache license 2.0. 20 | 21 | Links 22 | ===== 23 | 24 | * Thank you to [YourKit](http://www.yourkit.com) for the OSS Licence 25 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.fixedlengthdynamiccolumns; 2 | 3 | import java.io.FileReader; 4 | 5 | import net.sf.flatpack.DataSet; 6 | import net.sf.flatpack.DefaultParserFactory; 7 | import net.sf.flatpack.Parser; 8 | 9 | /** 10 | * @author zepernick 11 | * 12 | * TODO To change the template for this generated type comment go to Window - 13 | * Preferences - Java - Code Style - Code Templates 14 | */ 15 | public class FixedLengthWithPZMap { 16 | public static void main(final String[] args) throws Exception { 17 | final String mapping = getDefaultMapping(); 18 | final String data = getDefaultDataFile(); 19 | call(mapping, data); 20 | 21 | } 22 | 23 | public static String getDefaultDataFile() { 24 | return "PEOPLE-FixedLength.txt"; 25 | } 26 | 27 | public static String getDefaultMapping() { 28 | return "PEOPLE-FixedLength.pzmap.xml"; 29 | } 30 | 31 | public static void call(final String mapping, final String data) throws Exception { 32 | final Parser pzparser = DefaultParserFactory.getInstance().newFixedLengthParser(new FileReader(mapping), new FileReader(data)); 33 | final DataSet ds = pzparser.parse(); 34 | 35 | final String[] colNames = ds.getColumns(); 36 | 37 | while (ds.next()) { 38 | for (final String colName : colNames) { 39 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 40 | } 41 | 42 | System.out.println("==========================================================================="); 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/largedataset/fixedlengthdynamiccolumns/LargeFixedLengthWithPZMap.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.largedataset.fixedlengthdynamiccolumns; 2 | 3 | import java.io.FileReader; 4 | 5 | import net.sf.flatpack.DataSet; 6 | import net.sf.flatpack.brparse.BuffReaderFixedParser; 7 | import net.sf.flatpack.brparse.BuffReaderParseFactory; 8 | 9 | /** 10 | * @author zepernick 11 | * 12 | * TODO To change the template for this generated type comment go to Window - 13 | * Preferences - Java - Code Style - Code Templates 14 | */ 15 | public class LargeFixedLengthWithPZMap { 16 | public static void main(final String[] args) throws Exception { 17 | final String mapping = getDefaultMapping(); 18 | final String data = getDefaultDataFile(); 19 | call(mapping, data); 20 | } 21 | 22 | public static String getDefaultDataFile() { 23 | return "PEOPLE-FixedLength.txt"; 24 | } 25 | 26 | public static String getDefaultMapping() { 27 | return "PEOPLE-FixedLength.pzmap.xml"; 28 | } 29 | 30 | public static void call(final String mapping, final String data) throws Exception { 31 | String[] colNames = null; 32 | try (BuffReaderFixedParser pzparse = (BuffReaderFixedParser) BuffReaderParseFactory.getInstance() 33 | .newFixedLengthParser(new FileReader(mapping), new FileReader(data))) { 34 | 35 | final DataSet ds = pzparse.parse(); 36 | colNames = ds.getColumns(); 37 | 38 | while (ds.next()) { 39 | for (final String colName : colNames) { 40 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 41 | } 42 | 43 | System.out.println("==========================================================================="); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /flatpack/src/site/xdoc/code-metrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Benoit Xhenseval 5 | Code Metrics 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 |
49 | 50 | 51 | 52 |
-------------------------------------------------------------------------------- /flatpack-excel/src/site/xdoc/code-metrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Benoit Xhenseval 5 | Code Metrics 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 |
49 | 50 | 51 | 52 |
-------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | package net.sf.flatpack.converter; 34 | 35 | /** 36 | * Responsible for converting a column in IDataSet 37 | * to the desired Object. 38 | * 39 | * @author Paul Zepernick 40 | */ 41 | public interface Converter { 42 | 43 | /** 44 | * Returns the converted object from the 45 | * column in IDataSet 46 | * 47 | * @param valueToConvert 48 | * @return Object 49 | */ 50 | Object convertValue(String valueToConvert); 51 | } 52 | -------------------------------------------------------------------------------- /src/site/resources/press/press-release-2.3.0.txt: -------------------------------------------------------------------------------- 1 | Paul Zepernick and ObjectLab are pleased to announce release 2.3.0 of 2 | PZFileReader for Java 1.4+. 3 | 4 | Open Source flat file parser (CSV, Fixed Length, Custom) using XML 5 | to configure formats. 6 | 7 | http://pzfilereader.sourceforge.net 8 | 9 | PZFileReader is released under the business friendly Apache License v2.0. 10 | 11 | It is available immediately for download via SourceForge or the Maven Central 12 | Repository (both Maven 1 and Maven 2). The homepage has some very 13 | quick examples. 14 | 15 | The library is small, lightweight and does not force you to adopt a 16 | framework. 17 | 18 | The implementation is useful to any business that deal with flat files. 19 | The library allow you to define an XML mapping (or in a database) of 20 | the format of your file. Once this is done, the parsed data can be accessed 21 | via a simple name lookup mechanism. 22 | 23 | It is our aim to publish at some point some well know file formats for 24 | your immediate use. 25 | 26 | ObjectLab is not new to the open-source community having used numerous OS 27 | projects, It has recently launched the ObjectLab Kit family, including: 28 | - QALab (http://qalab.sourceforge.net), a tool that keeps track over-time 29 | of the static analysis results from FindBugs, Checkstyle, PMD, Cobertura etc. 30 | - DateCalculators (http://objectlabkit.sourceforge.net), a set of generic 31 | lightweight and thread-safe Date calculators for Business and Finance. 32 | - JTreeMap, (http://jtreemap.sourceforge.net), probably the only Java Open 33 | Source implementation of treemap/heatmaps, available as a Swing or SWT 34 | component. 35 | 36 | We would like to thanks our friends and colleagues at XXXX for their help, 37 | reviews and suggestions. 38 | 39 | Sorry for the long email... 40 | 41 | Feel free to pass on to people who may be interested. 42 | 43 | Enjoy!! 44 | 45 | Paul Zepernick and The ObjectLab Team (Benoit Xhenseval, Marcin Jekot) 46 | 47 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/FPStringUtils.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.util; 2 | 3 | /** 4 | * Thanks to the Apache Commons Contributors. 5 | * 6 | * @author Jakarta Commons 7 | */ 8 | public final class FPStringUtils { 9 | private FPStringUtils() { 10 | } 11 | 12 | /** 13 | *

Checks if a String is whitespace, empty ("") or null.

14 | * 15 | *
16 |      * PZStringUtils.isBlank(null)      = true
17 |      * PZStringUtils.isBlank("")        = true
18 |      * PZStringUtils.isBlank(" ")       = true
19 |      * PZStringUtils.isBlank("bob")     = false
20 |      * PZStringUtils.isBlank("  bob  ") = false
21 |      * 
22 | * 23 | * @param str the String to check, may be null 24 | * @return true if the String is null, empty or whitespace 25 | * @since 2.0 26 | */ 27 | public static boolean isBlank(final String str) { 28 | final int strLen = str == null ? 0 : str.length(); 29 | if (strLen == 0) { 30 | return true; 31 | } 32 | for (int i = 0; i < strLen; i++) { 33 | if (!Character.isWhitespace(str.charAt(i))) { 34 | return false; 35 | } 36 | } 37 | return true; 38 | } 39 | 40 | /** 41 | *

Checks if a String is not empty (""), not null and not whitespace only.

42 | * 43 | *
44 |      * PZStringUtils.isNotBlank(null)      = false
45 |      * PZStringUtils.isNotBlank("")        = false
46 |      * PZStringUtils.isNotBlank(" ")       = false
47 |      * PZStringUtils.isNotBlank("bob")     = true
48 |      * PZStringUtils.isNotBlank("  bob  ") = true
49 |      * 
50 | * 51 | * @param str the String to check, may be null 52 | * @return true if the String is 53 | * not empty and not null and not whitespace 54 | * @since 2.0 55 | */ 56 | public static boolean isNotBlank(final String str) { 57 | return !FPStringUtils.isBlank(str); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderDelimParser.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.Reader; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | import java.util.List; 8 | 9 | import net.sf.flatpack.InitialisationException; 10 | import net.sf.flatpack.structure.ColumnMetaData; 11 | import net.sf.flatpack.util.ParserUtils; 12 | 13 | /** 14 | * 15 | * 16 | * @author Paul Zepernick 17 | */ 18 | public class DBBuffReaderDelimParser extends BuffReaderDelimParser implements InterfaceBuffReaderParse { 19 | 20 | private final Connection con; 21 | 22 | /** 23 | * @param con 24 | * @param dataSourceReader 25 | * @param dataDefinition 26 | * @param delimiter 27 | * @param qualifier 28 | * @param ignoreFirstRecord 29 | */ 30 | public DBBuffReaderDelimParser(final Connection con, final Reader dataSourceReader, final String dataDefinition, final char delimiter, 31 | final char qualifier, final boolean ignoreFirstRecord) { 32 | super(dataSourceReader, delimiter, qualifier, ignoreFirstRecord); 33 | setDataDefinition(dataDefinition); 34 | this.con = con; 35 | } 36 | 37 | @Override 38 | protected void init() { 39 | try { 40 | final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); 41 | addToMetaData(cmds); 42 | 43 | if (cmds.isEmpty()) { 44 | throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); 45 | } 46 | setInitialised(true); 47 | } catch (final SQLException | FileNotFoundException e) { 48 | throw new InitialisationException(e); 49 | } 50 | } 51 | 52 | @Override 53 | protected boolean shouldCreateMDFromFile() { 54 | // The MetaData should always be pulled from the DB for this implementation 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/FPConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | package net.sf.flatpack.util; 34 | 35 | /** 36 | * @author xhensevb 37 | * 38 | */ 39 | public final class FPConstants { 40 | public static final String DETAIL_ID = "detail"; 41 | 42 | public static final String COL_IDX = "colIndex"; 43 | 44 | public static final String DELIMITED_FILE = "delimited"; 45 | 46 | public static final String FIXEDLENGTH_FILE = "fixed"; 47 | 48 | public static final int SPLITLINE_SIZE_INIT = 10; 49 | 50 | public static final char NO_QUALIFIER = '\0'; 51 | 52 | private FPConstants() { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/StreamingTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.io.StringReader; 4 | import java.math.BigDecimal; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | import junit.framework.TestCase; 9 | 10 | /** 11 | * JDK 8 Streaming test. 12 | * @author Benoit Xhenseval 13 | */ 14 | public class StreamingTest extends TestCase { 15 | 16 | private static class Test { 17 | private String itemName; 18 | private BigDecimal price; 19 | 20 | public String getItemName() { 21 | return itemName; 22 | } 23 | 24 | public void setItemName(final String itemName) { 25 | this.itemName = itemName; 26 | } 27 | 28 | public BigDecimal getPrice() { 29 | return price; 30 | } 31 | 32 | public void setPrice(final BigDecimal price) { 33 | this.price = price; 34 | } 35 | } 36 | 37 | public void testContains() { 38 | final String cols = "item,price,purchaseDate\r\n"// 39 | + "MacBook,1890.20,20140523\r\n"// 40 | + "Surface3,850.00,20140524\r\n"// 41 | ; 42 | final Parser p = CsvParserFactory.newInMemoryParser(new StringReader(cols)); 43 | final List ds = p.stream() // 44 | .map(t -> { 45 | final Test r = new Test(); 46 | r.setItemName(t.getString("item")); 47 | r.setPrice(t.getBigDecimal("price")); 48 | return r; 49 | })// Mapping from Record to Test 50 | .filter(t -> "Surface3".equals(t.getItemName())) // only keep the Surface3 (why???) 51 | .collect(Collectors.toList()); 52 | 53 | // test record 1 with Data in file! 54 | assertEquals("Size", 1, ds.size()); 55 | final Test test = ds.get(0); 56 | assertEquals("Item", "Surface3", test.getItemName()); 57 | assertTrue("Price", new BigDecimal("850").compareTo(test.getPrice()) == 0); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/multilinedelimitedrecord/DelimitedMultiLine.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.multilinedelimitedrecord; 2 | 3 | import java.io.FileReader; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import net.sf.flatpack.DataSet; 9 | import net.sf.flatpack.DefaultParserFactory; 10 | import net.sf.flatpack.Parser; 11 | 12 | /** 13 | * @author zepernick 14 | * 15 | * TODO To change the template for this generated type comment go to Window - 16 | * Preferences - Java - Code Style - Code Templates 17 | */ 18 | public class DelimitedMultiLine { 19 | private static final Logger LOG = LoggerFactory.getLogger(DelimitedMultiLine.class); 20 | 21 | public static void main(final String[] args) throws Exception { 22 | final String data = getDefaultDataFile(); 23 | try { 24 | call(data); 25 | } catch (final Exception e) { 26 | LOG.error("Issue", e); 27 | } 28 | } 29 | 30 | public static String getDefaultDataFile() { 31 | return "PEOPLE-CommaDelimitedWithQualifierMultiLine.txt"; 32 | } 33 | 34 | public static void call(final String data) throws Exception { 35 | // delimited by a comma 36 | // text qualified by double quotes 37 | // ignore first record 38 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new FileReader(data), ',', '\"'); 39 | final DataSet ds = pzparser.parse(); 40 | 41 | final String[] colNames = ds.getColumns(); 42 | 43 | while (ds.next()) { 44 | for (final String colName : colNames) { 45 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 46 | } 47 | 48 | System.out.println("==========================================================================="); 49 | } 50 | 51 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 52 | System.out.println("FOUND ERRORS IN FILE"); 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/ConvertDouble.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | 34 | package net.sf.flatpack.converter; 35 | 36 | import net.sf.flatpack.util.ParserUtils; 37 | 38 | /** 39 | * Returns a Double 40 | * Non numeric chars are removed from the string 41 | * before converting 42 | * 43 | * @author Paul Zepernick 44 | */ 45 | public class ConvertDouble implements Converter { 46 | 47 | /* 48 | * (non-Javadoc) 49 | * 50 | * @see net.sf.flatpack.converter#convertValue(java.lang.String) 51 | */ 52 | @Override 53 | public Object convertValue(final String valueToConvert) { 54 | return new Double(ParserUtils.stripNonDoubleChars(valueToConvert)); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/ConvertInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | 34 | package net.sf.flatpack.converter; 35 | 36 | import net.sf.flatpack.util.ParserUtils; 37 | 38 | /** 39 | * Returns a Integer 40 | * Non numeric chars are removed from the string 41 | * before converting 42 | * 43 | * @author Paul Zepernick 44 | */ 45 | public class ConvertInteger implements Converter { 46 | 47 | /* 48 | * (non-Javadoc) 49 | * 50 | * @see net.sf.flatpack.converter#convertValue(java.lang.String) 51 | */ 52 | @Override 53 | public Object convertValue(final String valueToConvert) { 54 | return Integer.valueOf(ParserUtils.stripNonLongChars(valueToConvert)); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/WriterOptions.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | /** 4 | * Defines options for various Writer behaviours 5 | * 6 | * @author Paul Zepernick 7 | */ 8 | public class WriterOptions { 9 | 10 | private boolean autoPrintHeader = true; 11 | private String replaceCarriageReturnWith = null; 12 | private String lineSeparator = System.lineSeparator(); 13 | 14 | /** 15 | * Returns a DelimiterWriterOptions instance 16 | * 17 | * @return DelimiterWriterOptions 18 | */ 19 | public static WriterOptions getInstance() { 20 | return new WriterOptions(); 21 | } 22 | 23 | /** 24 | * @return the noColumnMappings 25 | */ 26 | public boolean isAutoPrintHeader() { 27 | return autoPrintHeader; 28 | } 29 | 30 | /** 31 | * When this is set to true, the addRecordEntry(column, value) will throw an exception. You 32 | * must use addRecordEntry(value). 33 | * 34 | * @param autoPrintHeader the autoPrintHeader to set 35 | */ 36 | public WriterOptions autoPrintHeader(final boolean autoPrintHeader) { 37 | this.autoPrintHeader = autoPrintHeader; 38 | return this; 39 | } 40 | 41 | /** 42 | * Get the current line separator. Default is the system line separator. 43 | * @return 44 | */ 45 | public String getLineSeparator() { 46 | return lineSeparator; 47 | } 48 | 49 | /** 50 | * Set the line separator. 51 | * @param lineSeparator the line separator 52 | * @return 53 | */ 54 | public WriterOptions setLineSeparator(final String lineSeparator) { 55 | this.lineSeparator = lineSeparator; 56 | return this; 57 | } 58 | 59 | /** 60 | * Set the string to replace the CR with. 61 | */ 62 | public WriterOptions setReplaceCarriageReturnWith(final String replaceCarriageReturnWith) { 63 | this.replaceCarriageReturnWith = replaceCarriageReturnWith; 64 | return this; 65 | } 66 | 67 | public String getReplaceCarriageReturnWith() { 68 | return replaceCarriageReturnWith; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/numericsanddates/NumericsAndDates.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.numericsanddates; 2 | 3 | import java.io.FileReader; 4 | import java.text.SimpleDateFormat; 5 | 6 | import net.sf.flatpack.DataSet; 7 | import net.sf.flatpack.DefaultParserFactory; 8 | import net.sf.flatpack.Parser; 9 | 10 | /** 11 | * @author zepernick 12 | * 13 | * TODO To change the template for this generated type comment go to Window - 14 | * Preferences - Java - Code Style - Code Templates 15 | */ 16 | public class NumericsAndDates { 17 | public static void main(final String[] args) throws Exception { 18 | final String mapping = getDefaultMapping(); 19 | final String data = getDefaultDataFile(); 20 | call(mapping, data); 21 | } 22 | 23 | public static String getDefaultDataFile() { 24 | return "INVENTORY-CommaDelimitedWithQualifier.txt"; 25 | } 26 | 27 | public static String getDefaultMapping() { 28 | return "INVENTORY-Delimited.pzmap.xml"; 29 | } 30 | 31 | public static void call(final String mapping, final String data) throws Exception { 32 | // wll provide a clean format for printing the date to the screen 33 | final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); 34 | 35 | // delimited by a comma 36 | // text qualified by double quotes 37 | // ignore first record 38 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new FileReader(mapping), new FileReader(data), ',', '\"', true); 39 | final DataSet ds = pzparser.parse(); 40 | // demonstrates the casting abilities of FlatPack 41 | while (ds.next()) { 42 | System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)"); 43 | System.out.println("In Stock: " + ds.getInt("IN_STOCK") + " (int)"); 44 | System.out.println("Price: " + ds.getDouble("PRICE") + " (double)"); 45 | System.out.println("Received Dt: " + sdf.format(ds.getDate("LAST_RECV_DT")) + " (Date)"); 46 | System.out.println("==========================================================================="); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/util/FlatpackWriterUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package net.sf.flatpack.util; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import net.sf.flatpack.structure.ColumnMetaData; 13 | 14 | /** 15 | * Helper class to create ColumnMetaData and Mapping for the Writer Factory. 16 | * @author Benoit Xhenseval 17 | */ 18 | public final class FlatpackWriterUtil { 19 | private FlatpackWriterUtil() { 20 | } 21 | 22 | /** 23 | * Creates a Mapping for a WriterFactory for the given list of columns. 24 | * @param colsAsCsv comma-separated column names 25 | * @return a map to be used in, for instance, DelimiterWriterFactory 26 | */ 27 | public static Map buildParametersForColumns(final String colsAsCsv) { 28 | final Map mapping = new HashMap<>(); 29 | mapping.put(FPConstants.DETAIL_ID, buildColumns(colsAsCsv)); 30 | return mapping; 31 | } 32 | 33 | /** 34 | * Create a new list of ColumnMetaData based on a CSV list of column titles. 35 | * @param colsAsCsv 36 | * @return new list 37 | */ 38 | public static List buildColumns(final String colsAsCsv) { 39 | final List listCol = new ArrayList<>(); 40 | buildColumns(listCol, colsAsCsv); 41 | return listCol; 42 | } 43 | 44 | public static void buildColumns(final List listCol, final Collection cols) { 45 | if (cols != null) { 46 | cols.forEach(s -> listCol.add(new ColumnMetaData(s))); 47 | } 48 | } 49 | 50 | public static void buildColumns(final List listCol, final String cols) { 51 | if (cols != null) { 52 | for (final String s : cols.split(",")) { 53 | listCol.add(new ColumnMetaData(s)); 54 | } 55 | } 56 | } 57 | 58 | public static void buildColumns(final List listCol, final String... cols) { 59 | if (cols != null) { 60 | for (final String s : cols) { 61 | listCol.add(new ColumnMetaData(s)); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/lowlevelparse/LowLevelParse.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.lowlevelparse; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.util.List; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import net.sf.flatpack.util.ParserUtils; 12 | 13 | /* 14 | * Created on Nov 27, 2005 15 | * 16 | */ 17 | 18 | /** 19 | * @author zepernick 20 | * 21 | */ 22 | public class LowLevelParse { 23 | private static final Logger LOG = LoggerFactory.getLogger(LowLevelParse.class); 24 | 25 | public static void main(final String[] args) { 26 | final String data = getDefaultDataFile(); 27 | try { 28 | call(data); 29 | } catch (final Exception e) { 30 | LOG.error("issue", e); 31 | } 32 | } 33 | 34 | public static String getDefaultDataFile() { 35 | return "PEOPLE-CommaDelimitedWithQualifier.txt"; 36 | } 37 | 38 | public static void call(final String data) throws Exception { 39 | final File textFile = new File(data); 40 | String line = null; 41 | List elements = null; 42 | 43 | try (FileReader fr = new FileReader(textFile); BufferedReader br = new BufferedReader(fr)) { 44 | 45 | while ((line = br.readLine()) != null) { 46 | if (line.trim().length() == 0) { 47 | continue; 48 | } 49 | 50 | // tell the parser to split using a comma delimiter with a " 51 | // text qualifier. The text qualifier is optional, it can be 52 | // null 53 | // or empty 54 | elements = ParserUtils.splitLine(line, ',', '"', 10, false, false); 55 | 56 | for (int i = 0; i < elements.size(); i++) { 57 | System.out.println("Column " + i + ": " + (String) elements.get(i)); 58 | } 59 | 60 | System.out.println("==========================================================================="); 61 | } 62 | } catch (final Exception ex) { 63 | LOG.error("issue", ex); 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.delimitedcolumnnamesinfile; 2 | 3 | /* 4 | * Created on Nov 27, 2005 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | 10 | import net.sf.flatpack.DataError; 11 | import net.sf.flatpack.DataSet; 12 | import net.sf.flatpack.DefaultParserFactory; 13 | import net.sf.flatpack.Parser; 14 | import net.sf.flatpack.ordering.OrderBy; 15 | import net.sf.flatpack.ordering.OrderColumn; 16 | 17 | /** 18 | * @author zepernick 19 | * 20 | * TODO To change the template for this generated type comment go to Window - 21 | * Preferences - Java - Code Style - Code Templates 22 | */ 23 | public class DelimitedColumnNamesInFile { 24 | public static void main(final String[] args) throws Exception { 25 | String[] colNames = null; 26 | OrderBy orderby = null; 27 | 28 | // delimited by a comma 29 | // text qualified by double quotes 30 | // ignore first record 31 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"'); 32 | final DataSet ds = pzparser.parse(); 33 | 34 | // re order the data set by last name 35 | orderby = new OrderBy(); 36 | orderby.addOrderColumn(new OrderColumn("CITY", false)); 37 | orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); 38 | ds.orderRows(orderby); 39 | 40 | colNames = ds.getColumns(); 41 | 42 | while (ds.next()) { 43 | for (final String colName : colNames) { 44 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 45 | } 46 | 47 | System.out.println("==========================================================================="); 48 | } 49 | 50 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 51 | System.out.println("FOUND ERRORS IN FILE...."); 52 | for (int i = 0; i < ds.getErrors().size(); i++) { 53 | final DataError de = (DataError) ds.getErrors().get(i); 54 | System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo()); 55 | } 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/site/xdoc/code-metrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Benoit Xhenseval 5 | Code Metrics 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 |
49 | 50 | 51 | 52 |
-------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/largedataset/delimiteddynamiccolumns/LargeDelimitedWithPZMap.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.largedataset.delimiteddynamiccolumns; 2 | 3 | import java.io.FileReader; 4 | 5 | import net.sf.flatpack.DataSet; 6 | import net.sf.flatpack.brparse.BuffReaderDelimParser; 7 | import net.sf.flatpack.brparse.BuffReaderParseFactory; 8 | 9 | /** 10 | * @author zepernick 11 | * 12 | * TODO To change the template for this generated type comment go to Window - 13 | * Preferences - Java - Code Style - Code Templates 14 | */ 15 | public class LargeDelimitedWithPZMap { 16 | public static void main(final String[] args) throws Exception { 17 | final String mapping = getDefaultMapping(); 18 | final String data = getDefaultDataFile(); 19 | call(mapping, data); 20 | 21 | } 22 | 23 | public static String getDefaultDataFile() { 24 | return "PEOPLE-CommaDelimitedWithQualifier.txt"; 25 | } 26 | 27 | public static String getDefaultMapping() { 28 | return "PEOPLE-Delimited.pzmap.xml"; 29 | } 30 | 31 | public static void call(final String mapping, final String data) throws Exception { 32 | String[] colNames = null; 33 | try (FileReader pzmap = new FileReader(mapping); 34 | FileReader fileToParse = new FileReader(data); 35 | BuffReaderDelimParser pzparse = (BuffReaderDelimParser) BuffReaderParseFactory.getInstance().newDelimitedParser(pzmap, fileToParse, 36 | ',', '"', true)) { 37 | // delimited by a comma 38 | // text qualified by double quotes 39 | // ignore first record 40 | 41 | final DataSet ds = pzparse.parse(); 42 | 43 | colNames = ds.getColumns(); 44 | 45 | while (ds.next()) { 46 | for (final String colName : colNames) { 47 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 48 | } 49 | 50 | System.out.println("==========================================================================="); 51 | } 52 | 53 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 54 | System.out.println("FOUND ERRORS IN FILE"); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/InitialisationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | package net.sf.flatpack; 34 | 35 | /** 36 | * @author xhensevb 37 | * 38 | */ 39 | public class InitialisationException extends RuntimeException { 40 | private static final long serialVersionUID = -4181701730609348676L; 41 | 42 | /** 43 | * 44 | */ 45 | public InitialisationException() { 46 | super(); 47 | } 48 | 49 | /** 50 | * @param message 51 | */ 52 | public InitialisationException(final String message) { 53 | super(message); 54 | } 55 | 56 | /** 57 | * @param cause 58 | */ 59 | public InitialisationException(final Throwable cause) { 60 | super(cause); 61 | } 62 | 63 | /** 64 | * @param message 65 | * @param cause 66 | */ 67 | public InitialisationException(final String message, final Throwable cause) { 68 | super(message, cause); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/StreamingDataSet.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.util.Iterator; 4 | import java.util.NoSuchElementException; 5 | import java.util.Optional; 6 | import java.util.Spliterator; 7 | import java.util.Spliterators; 8 | import java.util.stream.Stream; 9 | import java.util.stream.StreamSupport; 10 | 11 | /** 12 | * New with jdk8, define stream() methods. You should 13 | * start using this BUT note that it will only return VALID Records, any invalid row will be skipped. 14 | * 15 | * @author Benoit Xhenseval 16 | * @since 3.4 17 | */ 18 | public interface StreamingDataSet extends RecordDataSet { 19 | /** 20 | * @since 4.0 21 | * @return a stream of Records 22 | */ 23 | default Stream stream() { 24 | return StreamSupport 25 | .stream(Spliterators.spliteratorUnknownSize(spliterator(), Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.IMMUTABLE), false); 26 | } 27 | 28 | /** 29 | * @since 4.0 30 | * @return a stream of Records 31 | */ 32 | default Stream parallelStream() { 33 | return StreamSupport 34 | .stream(Spliterators.spliteratorUnknownSize(spliterator(), Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.IMMUTABLE), true); 35 | } 36 | 37 | default Iterator spliterator() { 38 | return new Iterator() { 39 | Optional nextData = Optional.empty(); 40 | 41 | @Override 42 | public boolean hasNext() { 43 | if (nextData.isPresent()) { 44 | return true; 45 | } else { 46 | if (StreamingDataSet.this.next()) { 47 | nextData = getRecord(); 48 | } else { 49 | nextData = Optional.empty(); 50 | } 51 | return nextData.isPresent(); 52 | } 53 | } 54 | 55 | @Override 56 | public Record next() { 57 | if (nextData.isPresent() || hasNext()) { 58 | final Record line = nextData.isPresent() ? nextData.get() : null; 59 | nextData = Optional.empty(); 60 | return line; 61 | } else { 62 | throw new NoSuchElementException(); 63 | } 64 | } 65 | }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/converter/FPConvertException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | 34 | package net.sf.flatpack.converter; 35 | 36 | /** 37 | * Exception thrown when a conversion error occurs 38 | * 39 | * @author Paul Zepernick 40 | */ 41 | public class FPConvertException extends RuntimeException { 42 | private static final long serialVersionUID = 1L; 43 | 44 | public FPConvertException() { 45 | super(); 46 | } 47 | 48 | /** 49 | * @param message 50 | */ 51 | public FPConvertException(final String message) { 52 | super(message); 53 | } 54 | 55 | /** 56 | * @param cause 57 | */ 58 | public FPConvertException(final Throwable cause) { 59 | super(cause); 60 | } 61 | 62 | /** 63 | * @param message 64 | * @param cause 65 | */ 66 | public FPConvertException(final String message, final Throwable cause) { 67 | super(message, cause); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/site/resources/press/press-release-3.0.0.txt: -------------------------------------------------------------------------------- 1 | Paul Zepernick and ObjectLab are pleased to announce release 3.0.0 of 2 | PZFileReader for Java 1.4+. 3 | 4 | Open Source flat file parser (CSV, Fixed Length, Custom) using XML 5 | to configure formats. 6 | 7 | http://pzfilereader.sourceforge.net 8 | 9 | This is a major release with re-designed interfaces and performance gains 10 | of, in some cases, SEVERAL order of magnitude. Unfortunately, this release 11 | is not backward compatible. 12 | 13 | PZFileReader is released under the business friendly Apache License v2.0. 14 | 15 | The library is small, lightweight and does not force you to adopt a 16 | framework. 17 | 18 | The implementation is useful to any business that deal with flat files. 19 | Not only it can parse very quickly some CSV or any-user defined delimiter, 20 | this library can parse FIXED LENGTH files. 21 | 22 | The library allow you to define an XML mapping (or in a database) of 23 | the format of your file. Once this is done, the parsed data can be accessed 24 | via a simple name lookup mechanism. 25 | 26 | It is our aim to publish at some point some well know file formats for 27 | your immediate use. Please contribute if you have some standard files... 28 | 29 | It is available for download via SourceForge or the Maven Central 30 | Repository (both Maven 1 and Maven 2). The homepage has some very 31 | quick examples. 32 | 33 | ObjectLab is not new to the open-source community having used numerous OS 34 | projects, It has recently launched the ObjectLab Kit family, including: 35 | - QALab (http://qalab.sourceforge.net), a tool that keeps track over-time 36 | of the static analysis results from FindBugs, Checkstyle, PMD, Cobertura etc. 37 | - DateCalculators (http://objectlabkit.sourceforge.net), a set of generic 38 | lightweight and thread-safe Date calculators for Business and Finance. 39 | - JTreeMap, (http://jtreemap.sourceforge.net), probably the only Java Open 40 | Source implementation of treemap/heatmaps, available as a Swing or SWT 41 | component. 42 | - StatSVN, (http://www.statsvn.org), statistics for your Subversion repo. 43 | 44 | We would like to thanks our friends and colleagues for their help, 45 | reviews and suggestions. 46 | 47 | Sorry for the long email... 48 | 49 | Feel free to pass on to people who may be interested. 50 | 51 | Enjoy!! 52 | 53 | Paul Zepernick and The ObjectLab Team (Benoit Xhenseval, Marcin Jekot) 54 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/MultiLineTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.StringReader; 4 | import java.io.StringWriter; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import junit.framework.TestCase; 14 | import net.sf.flatpack.DataSet; 15 | import net.sf.flatpack.DefaultParserFactory; 16 | import net.sf.flatpack.structure.ColumnMetaData; 17 | import net.sf.flatpack.util.FPConstants; 18 | 19 | public class MultiLineTest extends TestCase { 20 | private static final String NEW_LINE = System.getProperty("line.separator"); 21 | private static final String CONTENT = "this is a" + NEW_LINE + " multiline " + NEW_LINE + "...."; 22 | 23 | private static final Logger LOG = LoggerFactory.getLogger(MultiLineTest.class); 24 | private Map mapping; 25 | 26 | @Override 27 | public void setUp() { 28 | mapping = new HashMap<>(); 29 | final List listColumns = new ArrayList<>(); 30 | for (final String column : new String[] { "Id", "Description" }) { 31 | final ColumnMetaData columnMetadata = new ColumnMetaData(); 32 | columnMetadata.setColName(column); 33 | listColumns.add(columnMetadata); 34 | } 35 | mapping.put(FPConstants.DETAIL_ID, listColumns); 36 | } 37 | 38 | public void testMultipleLine() throws Exception { 39 | final DelimiterWriterFactory factory = new DelimiterWriterFactory(mapping, ',', '"'); 40 | 41 | final StringWriter strWriter = new StringWriter(); 42 | final Writer flatMapWriter = factory.createWriter(strWriter, new WriterOptions().autoPrintHeader(false)); 43 | flatMapWriter.printHeader(); 44 | flatMapWriter.addRecordEntry("Id", "1"); 45 | flatMapWriter.addRecordEntry("Description", CONTENT); 46 | flatMapWriter.nextRecord(); 47 | flatMapWriter.flush(); 48 | flatMapWriter.close(); 49 | LOG.info("CSV is \n{}", strWriter.toString()); 50 | 51 | final String toRead = strWriter.toString(); 52 | final DataSet ds = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(toRead), ',', '"').parse(); 53 | if (ds.next()) { 54 | LOG.info("Parsed content \n{}", ds.getString("Description")); 55 | assertEquals(ds.getString("Description"), CONTENT); 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/delim/tab/TabDelimitedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Feb 26, 2006 3 | * 4 | * TODO To change the template for this generated file go to 5 | * Window - Preferences - Java - Code Style - Code Templates 6 | */ 7 | package net.sf.flatpack.delim.tab; 8 | 9 | import junit.framework.TestCase; 10 | import net.sf.flatpack.DataSet; 11 | 12 | /** 13 | * @author zepernick 14 | * 15 | * TODO To change the template for this generated type comment go to Window - 16 | * Preferences - Java - Code Style - Code Templates 17 | */ 18 | public class TabDelimitedTest extends TestCase { 19 | public TabDelimitedTest(final String name) { 20 | super(name); 21 | } 22 | 23 | // tests to make sure we have 0 errors 24 | public void testErrorCount() { 25 | DataSet ds = null; 26 | 27 | try { 28 | final TabDelimited testTab = new TabDelimited(); 29 | 30 | ds = testTab.getDsForTest(); 31 | 32 | // check that we had no errors 33 | assertEquals(0, ds.getErrors().size()); 34 | 35 | } catch (final Exception ex) { 36 | ex.printStackTrace(); 37 | } finally { 38 | } 39 | } 40 | 41 | // test to make sure we parsed the correct number 42 | // of rows in the file 43 | public void testRowCount() { 44 | DataSet ds = null; 45 | 46 | try { 47 | final TabDelimited testTab = new TabDelimited(); 48 | 49 | ds = testTab.getDsForTest(); 50 | 51 | // check that we parsed in the right amount of rows 52 | assertEquals(2, ds.getRowCount()); 53 | 54 | } catch (final Exception ex) { 55 | ex.printStackTrace(); 56 | } finally { 57 | } 58 | } 59 | 60 | // test to make sure we have the right number of column names from the file 61 | public void testColumnNameCount() { 62 | DataSet ds = null; 63 | 64 | try { 65 | final TabDelimited testTab = new TabDelimited(); 66 | 67 | ds = testTab.getDsForTest(); 68 | 69 | // check that we parsed in the right amount of column names 70 | assertEquals(5, ds.getColumns().length); 71 | 72 | } catch (final Exception ex) { 73 | ex.printStackTrace(); 74 | } finally { 75 | } 76 | } 77 | 78 | public static void main(final String[] args) { 79 | junit.textui.TestRunner.run(TabDelimitedTest.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/RecordTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack; 2 | 3 | import java.io.StringReader; 4 | import java.math.BigDecimal; 5 | import java.text.ParseException; 6 | import java.util.Calendar; 7 | import java.util.Date; 8 | import java.util.Optional; 9 | 10 | import junit.framework.TestCase; 11 | import net.sf.flatpack.util.FPConstants; 12 | 13 | /** 14 | * Test methods in the DataSet 15 | * 16 | * @author Paul Zepernick 17 | */ 18 | public class RecordTest extends TestCase { 19 | 20 | public void testContains() { 21 | final String cols = "stringCol,doubleCol,dateCol,bigDecimalCol,intCol\r\n"// 22 | + "hello,2.20,20140523,123.45,6\r\n"// 23 | + ",,,,"// 24 | ; 25 | final Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER); 26 | final StreamingDataSet ds = p.parseAsStream(); 27 | ds.next(); 28 | final Optional record1 = ds.getRecord(); 29 | 30 | // test record 1 with Data in file! 31 | assertEquals("rec1 string", "hello", record1.get().getString("stringCol")); 32 | assertTrue("rec1 doubleCol", Double.compare(2.2, record1.get().getDouble("doubleCol")) == 0); 33 | try { 34 | assertEquals("rec1 dateCol", new Date(114, Calendar.MAY, 23), record1.get().getDate("dateCol")); 35 | } catch (final ParseException e) { 36 | fail(); 37 | } 38 | assertEquals("rec1 intCol", 6, record1.get().getInt("intCol")); 39 | assertEquals("rec1 bigDecimalCol", new BigDecimal("123.45"), record1.get().getBigDecimal("bigDecimalCol")); 40 | 41 | // NOW RECORD 2 with ALL defaults 42 | ds.next(); 43 | final Optional record2 = ds.getRecord(); 44 | assertEquals("rec2 string", "Hi", record2.get().getString("stringCol", () -> "Hi")); 45 | assertTrue("rec2 doubleCol", Double.compare(3.76, record2.get().getDouble("doubleCol", () -> 3.76d)) == 0); 46 | try { 47 | assertEquals("rec2 dateCol", new Date(114, Calendar.JUNE, 11), record2.get().getDate("dateCol", () -> new Date(114, Calendar.JUNE, 11))); 48 | } catch (final ParseException e) { 49 | fail(); 50 | } 51 | assertEquals("rec2 intCol", 8, record2.get().getInt("intCol", () -> 8)); 52 | assertEquals("rec2 bigDecimalCol", new BigDecimal("555"), record2.get().getBigDecimal("bigDecimalCol", () -> new BigDecimal("555"))); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/columninfile/DelimitedColumnNamesInFileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Feb 26, 2006 3 | * 4 | * TODO To change the template for this generated file go to 5 | * Window - Preferences - Java - Code Style - Code Templates 6 | */ 7 | package net.sf.flatpack.columninfile; 8 | 9 | import junit.framework.TestCase; 10 | import net.sf.flatpack.DataSet; 11 | 12 | /** 13 | * @author zepernick 14 | * 15 | * TODO To change the template for this generated type comment go to Window - 16 | * Preferences - Java - Code Style - Code Templates 17 | */ 18 | public class DelimitedColumnNamesInFileTest extends TestCase { 19 | public DelimitedColumnNamesInFileTest(final String name) { 20 | super(name); 21 | } 22 | 23 | // tests to make sure we have 0 errors 24 | public void testErrorCount() { 25 | DataSet ds = null; 26 | 27 | try { 28 | final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); 29 | 30 | ds = testDelimted.getDsForTest(); 31 | 32 | // check that we had no errors 33 | assertEquals(0, ds.getErrors().size()); 34 | 35 | } catch (final Exception ex) { 36 | ex.printStackTrace(); 37 | } finally { 38 | } 39 | } 40 | 41 | // test to make sure we parsed the correct number 42 | // of rows in the file 43 | public void testRowCount() { 44 | DataSet ds = null; 45 | 46 | try { 47 | final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); 48 | 49 | ds = testDelimted.getDsForTest(); 50 | 51 | // check that we parsed in the right amount of rows 52 | assertEquals(6, ds.getRowCount()); 53 | 54 | } catch (final Exception ex) { 55 | ex.printStackTrace(); 56 | } finally { 57 | } 58 | } 59 | 60 | // test to make sure we have the right number of column names from the file 61 | public void testColumnNameCount() { 62 | DataSet ds = null; 63 | 64 | try { 65 | final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); 66 | 67 | ds = testDelimted.getDsForTest(); 68 | 69 | // check that we parsed in the right amount of column names 70 | assertEquals(6, ds.getColumns().length); 71 | 72 | } catch (final Exception ex) { 73 | ex.printStackTrace(); 74 | } finally { 75 | } 76 | } 77 | 78 | public static void main(final String[] args) { 79 | junit.textui.TestRunner.run(DelimitedColumnNamesInFileTest.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/exporttoexcel/DelimitedFileExportToExcel.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.exporttoexcel; 2 | 3 | /* 4 | * Created on Dec 31, 2004 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | import java.io.FileReader; 10 | 11 | import net.sf.flatpack.DataError; 12 | import net.sf.flatpack.DataSet; 13 | import net.sf.flatpack.DefaultParserFactory; 14 | import net.sf.flatpack.Parser; 15 | import net.sf.flatpack.excel.ExcelTransformer; 16 | import net.sf.flatpack.ordering.OrderBy; 17 | import net.sf.flatpack.ordering.OrderColumn; 18 | 19 | /** 20 | * @author zepernick 21 | * 22 | * TODO To change the template for this generated type comment go to Window - 23 | * Preferences - Java - Code Style - Code Templates 24 | */ 25 | public class DelimitedFileExportToExcel { 26 | public static void main(final String[] args) throws Exception { 27 | final String mapping = getDefaultMapping(); 28 | final String data = getDefaultDataFile(); 29 | call(mapping, data); 30 | 31 | } 32 | 33 | public static String getDefaultDataFile() { 34 | return "PEOPLE-CommaDelimitedWithQualifier.txt"; 35 | } 36 | 37 | public static String getDefaultMapping() { 38 | return "PEOPLE-Delimited.pzmap.xml"; 39 | } 40 | 41 | public static void call(final String mapping, final String data) throws Exception { 42 | // delimited by a comma 43 | // text qualified by double quotes 44 | // ignore first record 45 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new FileReader(mapping), new FileReader(data), ',', '"', true); 46 | final DataSet ds = pzparser.parse(); 47 | 48 | // re order the data set by last name 49 | final OrderBy orderby = new OrderBy(); 50 | orderby.addOrderColumn(new OrderColumn("CITY", false)); 51 | orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); 52 | ds.orderRows(orderby); 53 | 54 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 55 | for (int i = 0; i < ds.getErrors().size(); i++) { 56 | final DataError de = ds.getErrors().get(i); 57 | System.out.println("Error Msg: " + de.getErrorDesc() + " Line: " + de.getLineNo()); 58 | } 59 | } 60 | 61 | // lets write this file out to excel 62 | final File xlFile = new File("MyExcelExport.xls"); 63 | final ExcelTransformer xlTransformer = new ExcelTransformer(ds, xlFile); 64 | xlTransformer.writeExcelFile(); 65 | System.out.println("Excel Workbook Written To: " + xlFile.getAbsolutePath()); 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '27 2 * * 1' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java', 'python' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/writer/DoubleQualifierWriteReadTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.StringWriter; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.LinkedHashSet; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Optional; 11 | import java.util.Set; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import junit.framework.TestCase; 17 | import net.sf.flatpack.DataSet; 18 | import net.sf.flatpack.DelimiterParser; 19 | import net.sf.flatpack.Record; 20 | 21 | public class DoubleQualifierWriteReadTest extends TestCase { 22 | 23 | private static final Logger LOG = LoggerFactory.getLogger(DoubleQualifierWriteReadTest.class); 24 | 25 | public void testDelimiter() throws Exception { 26 | final java.io.Writer writer = new StringWriter(); 27 | 28 | final Set header = new LinkedHashSet(); 29 | header.add("Header1"); 30 | header.add("Header2"); 31 | header.add("Header3"); 32 | 33 | final List> dataList = new ArrayList>(); 34 | for (int i = 0; i < 2; i++) { 35 | final Map tempMap = new HashMap(header.size()); 36 | for (final String it : header) { 37 | tempMap.put(it, it + "_" + "Data \"\" " + i + " \""); 38 | } 39 | dataList.add(tempMap); 40 | } 41 | final DelimiterWriterFactory delimiterWriterFactory = new DelimiterWriterFactory(';', '"'); 42 | for (final String it : header) { 43 | delimiterWriterFactory.addColumnTitle(it); 44 | } 45 | final Writer createWriter = delimiterWriterFactory.createWriter(writer, WriterOptions.getInstance().autoPrintHeader(true)); 46 | 47 | for (final Map data : dataList) { 48 | for (final Map.Entry entry : data.entrySet()) { 49 | createWriter.addRecordEntry(entry.getKey(), entry.getValue()); 50 | } 51 | createWriter.nextRecord(); 52 | } 53 | createWriter.flush(); 54 | LOG.info("Content \n{}", writer.toString()); 55 | 56 | final ByteArrayInputStream file = new ByteArrayInputStream(writer.toString().getBytes()); 57 | final DelimiterParser parser = new DelimiterParser(file, ';', '"', false); 58 | final DataSet parse = parser.parse(); 59 | parse.next(); 60 | final Optional record = parse.getRecord(); 61 | assertEquals("Header2_Data \"\" 0 \"", record.get().getString("Header2")); 62 | LOG.info("Header2 \n{}", record.get().getString("Header2")); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/createsamplecsv/CSVTestFileCreator.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.createsamplecsv; 2 | 3 | import java.io.FileWriter; 4 | import java.io.PrintWriter; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /* 10 | * Created on Nov 30, 2005 11 | * 12 | */ 13 | 14 | /** 15 | * @author zepernick 16 | * 17 | * Creates a sample csv file with the specified number of columns and rows 18 | */ 19 | public class CSVTestFileCreator { 20 | private static final Logger LOG = LoggerFactory.getLogger(CSVTestFileCreator.class); 21 | 22 | public static void main(final String[] args) { 23 | int cols = 0; 24 | int rows = 0; 25 | 26 | if (args.length != 2) { 27 | printUsage(); 28 | return; 29 | } 30 | 31 | try { 32 | cols = Integer.parseInt(args[0]); 33 | rows = Integer.parseInt(args[1]); 34 | } catch (final Exception ex) { 35 | printUsage(); 36 | return; 37 | } 38 | 39 | createFile(cols, rows); 40 | } 41 | 42 | public static void createFile(final int cols, final int rows) { 43 | createFile(cols, rows, "SampleCSV.csv"); 44 | } 45 | 46 | public static void createFile(final int cols, final int rows, final String filename) { 47 | try (FileWriter fw = new FileWriter(filename); PrintWriter out = new PrintWriter(fw)) { 48 | 49 | // write the column names across the top of the file 50 | for (int i = 1; i <= cols; i++) { 51 | if (i > 1) { 52 | out.write(","); 53 | } 54 | out.write("\"column " + i + "\""); 55 | } 56 | out.write("\r\n"); 57 | out.flush(); 58 | 59 | // write the rows 60 | for (int i = 1; i <= rows; i++) { 61 | for (int j = 1; j <= cols; j++) { 62 | if (j > 1) { 63 | out.write(","); 64 | } 65 | out.write("\"data " + j + "\""); 66 | } 67 | 68 | out.write("\r\n"); 69 | out.flush(); 70 | if (i % 100000 == 0) { 71 | System.out.print("."); 72 | } 73 | } 74 | 75 | } catch (final Exception ex) { 76 | LOG.error("Issue", ex); 77 | } 78 | } 79 | 80 | private static void printUsage() { 81 | System.out.println("INVALID USAGE..."); 82 | System.out.println("PARAMETER 1 = # OF COLUMNS"); 83 | System.out.println("PARAMETER 2 = # OF ROWS"); 84 | System.out.println("Example - java CSVTestFileCreator 10 100"); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/delim/tab/TabDelimited.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.delim.tab; 2 | 3 | /* 4 | * Created on Nov 27, 2005 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | import java.io.FileReader; 10 | 11 | import net.sf.flatpack.DataError; 12 | import net.sf.flatpack.DataSet; 13 | import net.sf.flatpack.DefaultParserFactory; 14 | import net.sf.flatpack.Parser; 15 | 16 | /** 17 | * @author zepernick 18 | * 19 | * TODO To change the template for this generated type comment go to Window - 20 | * Preferences - Java - Code Style - Code Templates 21 | */ 22 | public class TabDelimited { 23 | public static void main(final String[] args) throws Exception { 24 | String[] colNames = null; 25 | File tmpFile = null; 26 | 27 | // delimited by a comma 28 | // text qualified by double quotes 29 | // ignore first record 30 | tmpFile = new File("net/sf/flatpack/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"); 31 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(tmpFile, '\t', '\"'); 32 | final DataSet ds = pzparser.parse(); 33 | 34 | // re order the data set by last name 35 | /* 36 | * orderby = new OrderBy(); orderby.addOrderColumn(new 37 | * OrderColumn("CITY",false)); orderby.addOrderColumn(new 38 | * OrderColumn("LASTNAME",true)); ds.orderRows(orderby); 39 | */ 40 | 41 | colNames = ds.getColumns(); 42 | 43 | while (ds.next()) { 44 | for (final String colName : colNames) { 45 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 46 | } 47 | 48 | System.out.println("==========================================================================="); 49 | } 50 | 51 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 52 | System.out.println("FOUND ERRORS IN FILE...."); 53 | for (int i = 0; i < ds.getErrors().size(); i++) { 54 | final DataError de = ds.getErrors().get(i); 55 | System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo()); 56 | } 57 | } 58 | 59 | } 60 | 61 | // used for Junit test 62 | 63 | public DataSet getDsForTest() throws Exception { 64 | final Parser parser = DefaultParserFactory.getInstance() 65 | .newDelimitedParser(new FileReader("src/test/java/net/sf/flatpack/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"), '\t', '\"'); 66 | 67 | parser.setHandlingShortLines(true); 68 | 69 | return parser.parse(); 70 | 71 | // return new DataSet(new File("src/test/java/net/sf/flatpack/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"), "\t", "\"", true); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/columninfile/DelimitedColumnNamesInFile.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.columninfile; 2 | 3 | /* 4 | * Created on Nov 27, 2005 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | 10 | import net.sf.flatpack.DataError; 11 | import net.sf.flatpack.DataSet; 12 | import net.sf.flatpack.DefaultParserFactory; 13 | import net.sf.flatpack.Parser; 14 | import net.sf.flatpack.ordering.OrderBy; 15 | import net.sf.flatpack.ordering.OrderColumn; 16 | 17 | /** 18 | * @author zepernick 19 | * 20 | * TODO To change the template for this generated type comment go to Window - 21 | * Preferences - Java - Code Style - Code Templates 22 | */ 23 | public class DelimitedColumnNamesInFile { 24 | public static void main(final String[] args) throws Exception { 25 | // delimited by a comma 26 | // text qualified by double quotes 27 | // ignore first record 28 | final Parser pzparser = DefaultParserFactory.getInstance() 29 | .newDelimitedParser(new File("net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"'); 30 | final DataSet ds = pzparser.parse(); 31 | 32 | // re order the data set by last name 33 | OrderBy orderby = new OrderBy(); 34 | orderby.addOrderColumn(new OrderColumn("CITY", false)); 35 | orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); 36 | ds.orderRows(orderby); 37 | 38 | String[] colNames = ds.getColumns(); 39 | 40 | while (ds.next()) { 41 | for (final String colName : colNames) { 42 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 43 | } 44 | 45 | System.out.println("==========================================================================="); 46 | } 47 | 48 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 49 | System.out.println("FOUND ERRORS IN FILE...."); 50 | for (int i = 0; i < ds.getErrors().size(); i++) { 51 | final DataError de = ds.getErrors().get(i); 52 | System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo()); 53 | } 54 | } 55 | 56 | } 57 | 58 | // used for Junit test 59 | 60 | public DataSet getDsForTest() throws Exception { 61 | 62 | final Parser parser = DefaultParserFactory.getInstance() 63 | .newDelimitedParser(new File("src/test/java/net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"'); 64 | 65 | return parser.parse(); 66 | 67 | // return new DataSet(new 68 | // File("src/test/java/net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), 69 | // ",", 70 | // "\"", false); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/xml/ResolveLocalDTD.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack. 3 | * 4 | * Based in London, we are world leaders in the design and development 5 | * of bespoke applications for the securities financing markets. 6 | * 7 | * Click here to learn more 8 | * ___ _ _ _ _ _ 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 13 | * |__/ 14 | * 15 | * www.ObjectLab.co.uk 16 | * 17 | * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ 18 | * 19 | * Copyright 2006 the original author or authors. 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 22 | * use this file except in compliance with the License. You may obtain a copy of 23 | * the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 30 | * License for the specific language governing permissions and limitations under 31 | * the License. 32 | */ 33 | package net.sf.flatpack.xml; 34 | 35 | import java.io.IOException; 36 | import java.net.URL; 37 | import java.util.Locale; 38 | 39 | import org.xml.sax.EntityResolver; 40 | import org.xml.sax.InputSource; 41 | import org.xml.sax.SAXException; 42 | 43 | /** 44 | * Resolves a local copy of the DTD instead of having to pull 45 | * over the internet from the SF site 46 | * 47 | * @author Paul Zepernick 48 | */ 49 | public final class ResolveLocalDTD implements EntityResolver { 50 | 51 | /* 52 | * (non-Javadoc) 53 | * 54 | * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, 55 | * java.lang.String) 56 | */ 57 | @Override 58 | public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException { 59 | if (!systemId.toLowerCase(Locale.getDefault()).startsWith("http://")) { 60 | final URL resource = getClass().getResource("flatpack.dtd"); 61 | 62 | if (resource != null) { 63 | return new InputSource(resource.openStream()); 64 | } else { 65 | // should probably not happen, this may indicate that the dtd has been 66 | // removed from the jar for some reason 67 | throw new IOException("could not load dtd resource from jar!!"); 68 | } 69 | } 70 | 71 | // must be pulling from the web, stick with default implementation 72 | return null; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/site/xdoc/press/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | On the web... 4 | 5 | 6 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 |

25 | 26 |

27 | 28 | 29 | 33 | 34 | 35 | 80 |
81 | 82 | 83 |
-------------------------------------------------------------------------------- /src/site/resources/press/press-release-3.1.0.txt: -------------------------------------------------------------------------------- 1 | Paul Zepernick and ObjectLab are pleased to announce release 3.1.0 of 2 | FlatPack for Java 1.4+. 3 | 4 | FlatPack is the new name for PZFileReader as the project has outgrown 5 | the initial scope of reading files... 6 | 7 | Open Source flat file parser (CSV, Fixed Length, Custom) using XML 8 | to configure formats. 9 | 10 | http://flatpack.sourceforge.net 11 | 12 | This is an important release with a new name and package structure. 13 | Users of previous version should find it easy to migrate as most classes 14 | have kept their original name. 15 | 16 | A major development is the experimental release of writers for exporting 17 | DataSets. We would like to thank Dirk and Holger from the Mule Project 18 | for their kind contribution to FlatPack. We're looking forward to the 19 | result of using FlatPack in Mule, a great Open Source ESB. 20 | 21 | This release also adds a few convenience methods on a DataSet and the 22 | Parser classes, fixes a couple of bugs. 23 | More on changes at: http://flatpack.sf.net/changes-report.html 24 | 25 | 26 | FlatPack is released under the business friendly Apache License v2.0. 27 | 28 | The library is small, lightweight and does not force you to adopt a 29 | framework. 30 | 31 | The implementation is useful to any business that deal with flat files. 32 | Not only it can parse very quickly some CSV or any-user defined delimiter, 33 | this library can parse FIXED LENGTH files. 34 | 35 | The library allow you to define an XML mapping (or in a database) of 36 | the format of your file. Once this is done, the parsed data can be accessed 37 | via a simple name lookup mechanism. 38 | 39 | It is our aim to publish at some point some well know file formats for 40 | your immediate use. Please contribute if you have some standard files... 41 | 42 | It is available for download via SourceForge or the Maven Central 43 | Repository (both Maven 1 and Maven 2). The homepage has some very 44 | quick examples. 45 | 46 | Maven Repositories: 47 | M1: http://objectlabkit.sf.net/m1-repo 48 | M2: http://objectlabkit.sf.net/m2-repo 49 | 50 | ObjectLab is not new to the open-source community having used numerous OS 51 | projects, It has recently launched the ObjectLab Kit family, including: 52 | - QALab (http://qalab.sourceforge.net), a tool that keeps track over-time 53 | of the static analysis results from FindBugs, Checkstyle, PMD, Cobertura etc. 54 | - DateCalculators (http://objectlabkit.sourceforge.net), a set of generic 55 | lightweight and thread-safe Date calculators for Business and Finance. 56 | - JTreeMap, (http://jtreemap.sourceforge.net), probably the only Java Open 57 | Source implementation of treemap/heatmaps, available as a Swing or SWT 58 | component. 59 | - StatSVN, (http://www.statsvn.org), statistics for your Subversion repo. 60 | 61 | We would like to thanks our friends and colleagues for their help, 62 | reviews and suggestions. 63 | 64 | Sorry for the long email... 65 | 66 | Feel free to pass on to people who may be interested. 67 | 68 | Enjoy!! 69 | 70 | Paul Zepernick and Benoit Xhenseval 71 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/parserutils/FixedWidthParserUtilsTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.parserutils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import junit.framework.TestCase; 7 | import net.sf.flatpack.structure.ColumnMetaData; 8 | import net.sf.flatpack.util.FixedWidthParserUtils; 9 | import net.sf.flatpack.util.ParserUtils; 10 | 11 | /** 12 | * Test the functionality of a fixed width parse 13 | * 14 | * @author Paul Zepernick 15 | */ 16 | public class FixedWidthParserUtilsTest extends TestCase { 17 | 18 | /** 19 | * Test fixed width text 20 | * 21 | */ 22 | public void testFixedParse() { 23 | check(new String[] { "test", "test", "test" }, new int[] { 5, 10, 20 }, new String[] { "test", "test", "test" }, true, false); 24 | 25 | check(new String[] { "test with some space", "test", "test" }, new int[] { 300, 10, 20 }, 26 | new String[] { "test with some space", "test", "test" }, true, false); 27 | 28 | final String[] textWithLeadingAndTrailing = { " test with leading and trailing ", " test ", "test" }; 29 | check(textWithLeadingAndTrailing, new int[] { 36, 7, 4 }, textWithLeadingAndTrailing, true, true); 30 | check(textWithLeadingAndTrailing, new int[] { 36, 7, 4 }, new String[] { " test with leading and trailing", " test", "test" }, true, false); 31 | check(textWithLeadingAndTrailing, new int[] { 36, 7, 4 }, new String[] { "test with leading and trailing ", "test ", "test" }, false, 32 | true); 33 | } 34 | 35 | private void check(final String[] columnData, final int[] lengths, final String[] expected, final boolean preserveLeading, 36 | final boolean preserveTrailing) { 37 | final List columnMetaData = new ArrayList(); 38 | 39 | assertEquals("data and col lengths different size...", columnData.length, lengths.length); 40 | 41 | for (final int length : lengths) { 42 | final ColumnMetaData cmd = new ColumnMetaData(); 43 | cmd.setColLength(length); 44 | columnMetaData.add(cmd); 45 | } 46 | 47 | final StringBuilder lineToParse = new StringBuilder(); 48 | for (int i = 0; i < columnData.length; i++) { 49 | // padd each column 50 | lineToParse.append(columnData[i]).append(ParserUtils.padding(lengths[i] - columnData[i].length(), ' ')); 51 | } 52 | 53 | final List splitResult = FixedWidthParserUtils.splitFixedText(columnMetaData, lineToParse.toString(), preserveLeading, 54 | preserveTrailing); 55 | 56 | // compare the parse results to the expected results 57 | assertEquals("did not return correct number of cols...", expected.length, splitResult.size()); 58 | 59 | for (int i = 0; i < expected.length; i++) { 60 | assertEquals("col values don't match...", expected[i], splitResult.get(i)); 61 | } 62 | 63 | } 64 | 65 | public static void main(final String[] args) { 66 | junit.textui.TestRunner.run(FixedWidthParserUtilsTest.class); 67 | } 68 | } -------------------------------------------------------------------------------- /src/site/xdoc/history.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Benoit Xhenseval 4 | History 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 |

The base code for FlatPack was started as PZFileReader. At the time, I was writing quite 25 | a few file imports which were mostly fixed width. I kept encountering the same problem; we had to add something 26 | to the file layout somewhere, or expand a length, thus changing all the substrings in the code.

27 | 28 |

I decided that there must be a way to map out the file so that changing the file layout would not break the code. This is when 29 | PZFileReader was born, although it did not have a name as of yet. The first iteration of the code had the field 30 | mappings in a database table, and seemed to work very well for my projects at work.

31 | 32 |

At that time, I had been spending a lot of time on the Java Sun forums. The same questions kept re-appearing. 33 | How do I read a CSV file, or how do I read fixed text. I decided that with a little more work, my project could 34 | benefit the community. Whenever I had some free time at home I started to make enhancements to the code.

35 | 36 |

I developed a way to map columns with an XML file instead of having to store the mapping in a database, and 37 | a generic parser to handle any kind of delimited file, the delimited and qualifier were passed into the constructor.

38 | 39 |

This brings us to today. Since the first release, there have been many fixes / enhancements to the parser, 40 | mainly the delimited parser. My hope is that this project will take off and become a fixture in the community. 41 | If you have a good experience with this project, and it has benefited you in some way, please spread the word.

42 | 43 |

Recently, ObjectLab from the UK has decided to offer some support to PZFileReader. 44 | PZFileReader is now "kind of" part of the ObjectLab Kit family, a 'support' group for useful open source projects. 45 | They developed the Maven build, the website and are active members of this project. They are world leaders in the design 46 | and development of bespoke applications for the Securities Finance Industry.

47 | 48 |

In May 2007, we realised that PZFileReader was actually much more than what the name implied... we then renamed it FlatPack!

49 |
50 | 51 | 52 |
-------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/brparse/BuffReaderFixedParserTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import java.io.StringReader; 4 | 5 | import junit.framework.TestCase; 6 | import net.sf.flatpack.DefaultDataSet; 7 | import net.sf.flatpack.Parser; 8 | import net.sf.flatpack.structure.Row; 9 | 10 | /** 11 | * Test misc methods in the BuffReaderFixedParser class 12 | * 13 | * @author Tim Zimmerman 14 | */ 15 | public class BuffReaderFixedParserTest extends TestCase { 16 | 17 | private static final String PZ_MAP_XML_STRING = "\n" + "\n" + "\n" 18 | + " \n" + " \n" 19 | + " \n" + " "; 20 | private static final String EXACT_LINE_STRING = "exactly thirty characters"; 21 | private static final String SHORT_LINE_STRING = "shorter than thirty"; 22 | private static final String LONG_LINE_STRING = "longer than thirty characters"; 23 | 24 | private Parser fixedWidthParser; 25 | 26 | public String parseRawData(final String pzMapXML, final String dataString) { 27 | String rawData = null; 28 | final StringReader pzReader = new StringReader(pzMapXML); 29 | final StringReader lineReader = new StringReader(dataString); 30 | try { 31 | final Parser parser = BuffReaderParseFactory.getInstance().newFixedLengthParser(pzReader, lineReader); 32 | assertTrue("Parser is not an instance of " + BuffReaderFixedParser.class, parser instanceof BuffReaderFixedParser); 33 | 34 | final BuffReaderFixedParser fixedWidthParser = (BuffReaderFixedParser) parser; 35 | fixedWidthParser.setIgnoreExtraColumns(true); 36 | fixedWidthParser.setHandlingShortLines(true); 37 | fixedWidthParser.setStoreRawDataToDataSet(true); 38 | 39 | final DefaultDataSet dataset = (DefaultDataSet) fixedWidthParser.parse(); 40 | final Row parsedRow = fixedWidthParser.buildRow(dataset); 41 | rawData = parsedRow.getRawData(); 42 | } finally { 43 | pzReader.close(); 44 | lineReader.close(); 45 | } 46 | return rawData; 47 | } 48 | 49 | public void testBuildExactRow() { 50 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, EXACT_LINE_STRING); 51 | assertTrue("The raw data does not match the orginal line", rawData.equals(EXACT_LINE_STRING)); 52 | } 53 | 54 | public void testBuildShortRow() { 55 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, SHORT_LINE_STRING); 56 | assertTrue("The raw data does not match the orginal line", rawData.equals(SHORT_LINE_STRING)); 57 | } 58 | 59 | public void testBuildLongRow() { 60 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, LONG_LINE_STRING); 61 | assertTrue("The raw data does not match the orginal line", rawData.equals(LONG_LINE_STRING)); 62 | } 63 | 64 | public static void main(final String[] args) { 65 | junit.textui.TestRunner.run(BuffReaderFixedParserTest.class); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/brparse/BuffReaderDelimParserTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.brparse; 2 | 3 | import java.io.StringReader; 4 | 5 | import junit.framework.TestCase; 6 | import net.sf.flatpack.DefaultDataSet; 7 | import net.sf.flatpack.Parser; 8 | import net.sf.flatpack.structure.Row; 9 | 10 | /** 11 | * Test misc methods in the BuffReaderFixedParser class 12 | * 13 | * @author Tim Zimmerman 14 | */ 15 | public class BuffReaderDelimParserTest extends TestCase { 16 | 17 | private static final char DELIMTER = ','; 18 | private static final char QUALIFIER = '\"'; 19 | private static final String PZ_MAP_XML_STRING = "\n" + "\n" + "\n" 20 | + " \n" + " \n" + " \n" 21 | + " \n" + " "; 22 | private static final String EXACT_LINE_STRING = "exactly,four,values,here"; 23 | private static final String SHORT_LINE_STRING = "shorter,than,four"; 24 | private static final String LONG_LINE_STRING = "longer,than,four,fields,fifth"; 25 | 26 | public String parseRawData(final String pzMapXML, final String dataString) { 27 | String rawData = null; 28 | final StringReader pzReader = new StringReader(pzMapXML); 29 | final StringReader lineReader = new StringReader(dataString); 30 | try { 31 | final Parser parser = BuffReaderParseFactory.getInstance().newDelimitedParser(pzReader, lineReader, DELIMTER, QUALIFIER, false); 32 | assertTrue("Parser is not an instance of " + BuffReaderDelimParser.class, parser instanceof BuffReaderDelimParser); 33 | 34 | final BuffReaderDelimParser delimParser = (BuffReaderDelimParser) parser; 35 | delimParser.setIgnoreExtraColumns(true); 36 | delimParser.setHandlingShortLines(true); 37 | delimParser.setStoreRawDataToDataSet(true); 38 | 39 | final DefaultDataSet dataset = (DefaultDataSet) delimParser.parse(); 40 | final Row parsedRow = delimParser.buildRow(dataset); 41 | rawData = parsedRow.getRawData(); 42 | } finally { 43 | pzReader.close(); 44 | lineReader.close(); 45 | } 46 | return rawData; 47 | } 48 | 49 | public void testBuildExactRow() { 50 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, EXACT_LINE_STRING); 51 | assertTrue("The raw data does not match the orginal line", rawData.equals(EXACT_LINE_STRING)); 52 | } 53 | 54 | public void testBuildShortRow() { 55 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, SHORT_LINE_STRING); 56 | assertTrue("The raw data does not match the orginal line", rawData.equals(SHORT_LINE_STRING)); 57 | } 58 | 59 | public void testBuildLongRow() { 60 | final String rawData = this.parseRawData(PZ_MAP_XML_STRING, LONG_LINE_STRING); 61 | assertTrue("The raw data does not match the orginal line", rawData.equals(LONG_LINE_STRING)); 62 | } 63 | 64 | public static void main(final String[] args) { 65 | junit.textui.TestRunner.run(BuffReaderDelimParserTest.class); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.writer; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * This class encapsulates the writer that's used to output the data. 10 | * @author Dirk Holmes and Holger Holger Hoffstatte 11 | */ 12 | public abstract class AbstractWriter implements Writer { 13 | private final BufferedWriter writer; 14 | private Map rowMap; 15 | protected String lineSeparator = System.lineSeparator(); 16 | 17 | public AbstractWriter(final java.io.Writer output) { 18 | super(); 19 | writer = new BufferedWriter(output); 20 | } 21 | 22 | public AbstractWriter(final java.io.Writer writer, final String lineSeparator) { 23 | super(); 24 | this.writer = new BufferedWriter(writer); 25 | this.lineSeparator = lineSeparator; 26 | } 27 | 28 | @Override 29 | public Writer addRecordEntry(final String columnName, final Object value) { 30 | if (rowMap == null) { 31 | rowMap = new HashMap<>(); 32 | } 33 | 34 | if (!validateColumnTitle(columnName)) { 35 | throw new IllegalArgumentException("unknown column: \"" + columnName + "\""); 36 | } 37 | rowMap.put(columnName, value); 38 | return this; 39 | } 40 | 41 | /** 42 | * Subclasses must implement this method to perform validation of 43 | * columnTitle. 44 | * 45 | * @param columnTitle title of the column to be filled 46 | * @return true if the column title is valid else return 47 | * false. 48 | */ 49 | protected abstract boolean validateColumnTitle(String columnTitle); 50 | 51 | /** 52 | * Writes a newline to the output and discards the rowMap. 53 | *

54 | * This method must be overridden by subclasses to write out the record data 55 | * stored in rowMap. Overriders must call 56 | * super.nextRecord() as the last call in their implementation. 57 | */ 58 | @Override 59 | public Writer nextRecord() throws IOException { 60 | // the row should have been written out by the subclass so it's safe to 61 | // discard it here 62 | rowMap = null; 63 | writer.write(this.lineSeparator); 64 | return this; 65 | } 66 | 67 | protected void write(final Object val) throws IOException { 68 | Object value = val == null ? "" : val; 69 | // TODO DO: converter/formatter for converting value to string? 70 | writer.write(value.toString()); 71 | } 72 | 73 | protected void write(final char character) throws IOException { 74 | writer.write(character); 75 | } 76 | 77 | protected void write(final char[] characters) throws IOException { 78 | writer.write(characters); 79 | } 80 | 81 | @Override 82 | public Writer flush() throws IOException { 83 | writer.flush(); 84 | return this; 85 | } 86 | 87 | @Override 88 | public void close() throws IOException { 89 | writer.flush(); 90 | writer.close(); 91 | } 92 | 93 | protected Map getRowMap() { 94 | return rowMap; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.csvheaderandtrailer; 2 | 3 | /* 4 | * Created on Dec 31, 2004 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | 10 | import net.sf.flatpack.DataSet; 11 | import net.sf.flatpack.DefaultParserFactory; 12 | import net.sf.flatpack.Parser; 13 | 14 | /** 15 | * @author zepernick 16 | * 17 | * TODO To change the template for this generated type comment go to Window - 18 | * Preferences - Java - Code Style - Code Templates 19 | */ 20 | public class CSVHeaderAndTrailer { 21 | public static void main(final String[] args) throws Exception { 22 | call(getDefaultMapping(), getDefaultDataFile()); 23 | } 24 | 25 | public static String getDefaultMapping() { 26 | return "PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml"; 27 | } 28 | 29 | public static String getDefaultDataFile() { 30 | return "PEOPLE-CommaDelimitedWithQualifier.txt"; 31 | } 32 | 33 | public static void call(final String mapping, final String data) throws Exception { 34 | final File mapFile = new File(mapping); 35 | final File dataFile = new File(data); 36 | // delimited by a comma 37 | // text qualified by double quotes 38 | // ignore first record 39 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(mapFile, dataFile, ',', '\"', true); 40 | final DataSet ds = pzparser.parse(); 41 | while (ds.next()) { 42 | 43 | if (ds.isRecordID("header")) { 44 | System.out.println(">>>>>>Found Header Record"); 45 | System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR")); 46 | System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA")); 47 | System.out.println("==========================================================================="); 48 | continue; 49 | } 50 | 51 | if (ds.isRecordID("trailer")) { 52 | System.out.println(">>>>>>Found Trailer Record"); 53 | System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR")); 54 | System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA")); 55 | System.out.println("==========================================================================="); 56 | continue; 57 | } 58 | 59 | System.out.println("COLUMN NAME: FIRSTNAME VALUE: " + ds.getString("FIRSTNAME")); 60 | System.out.println("COLUMN NAME: LASTNAME VALUE: " + ds.getString("LASTNAME")); 61 | System.out.println("COLUMN NAME: ADDRESS VALUE: " + ds.getString("ADDRESS")); 62 | System.out.println("COLUMN NAME: CITY VALUE: " + ds.getString("CITY")); 63 | System.out.println("COLUMN NAME: STATE VALUE: " + ds.getString("STATE")); 64 | System.out.println("COLUMN NAME: ZIP VALUE: " + ds.getString("ZIP")); 65 | System.out.println("==========================================================================="); 66 | } 67 | 68 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 69 | System.out.println("FOUND ERRORS IN FILE"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/jsptableexample/pzfilereaderwebsamples/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ page language="java" import="java.util.*,net.sf.pzfilereader.*,net.sf.pzfilereader.ordering.*,java.io.File" %> 3 | 4 | 5 | 6 | 7 | 8 | PZ File Reader JSP Sample 9 | 10 | 11 | <% 12 | OrderBy order = null; 13 | try{ 14 | 15 | File mappingFile = null; 16 | File txtFile = null; 17 | String appDirectory = null; 18 | 19 | //find out where this application is installed 20 | appDirectory = getServletContext().getRealPath(""); 21 | 22 | mappingFile = new File (appDirectory + "/PEOPLE.pzmap.xml"); 23 | txtFile = new File (appDirectory + "/PEOPLE.txt"); 24 | 25 | //read in the file 26 | final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mappingFile, 27 | txtFile, ',', 0, false) ; 28 | final DataSet ds = pzparser.parse(); 29 | 30 | 31 | //check to see if there is a paramter in the request that is telling us what column to sort by 32 | if (request.getParameter("orderby") != null && 33 | request.getParameter("orderby").trim().length() > 0){ 34 | 35 | //sort the file by what was passed in the request 36 | order = new OrderBy(); 37 | order.addOrderColumn(new OrderColumn(request.getParameter("orderby"),false)); //set boolean to true for DESC sort 38 | ds.orderRows(order); 39 | 40 | } 41 | 42 | }catch(Exception ex){ 43 | out.println("Error: " + ex); 44 | } 45 | %> 46 | 47 | 48 | 49 | 54 | 59 | 64 | 69 | 74 | 79 | 80 | 81 | <% 82 | while (ds.next()){ 83 | %> 84 | 85 | 86 | 89 | 92 | 95 | 98 | 101 | 104 | 105 | 106 | 107 | <% 108 | } 109 | %> 110 | 111 |
50 | 51 | First Name 52 | 53 | 55 | 56 | Last Name 57 | 58 | 60 | 61 | Address 62 | 63 | 65 | 66 | City 67 | 68 | 70 | 71 | State 72 | 73 | 75 | 76 | Zip 77 | 78 |
87 | <%=ds.getString("FIRSTNAME")%> 88 | 90 | <%=ds.getString("LASTNAME")%> 91 | 93 | <%=ds.getString("ADDRESS")%> 94 | 96 | <%=ds.getString("CITY")%> 97 | 99 | <%=ds.getString("STATE")%> 100 | 102 | <%=ds.getString("ZIP")%> 103 |
112 | 113 | 114 | -------------------------------------------------------------------------------- /flatpack/src/main/java/net/sf/flatpack/xml/MetaData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package net.sf.flatpack.xml; 5 | 6 | import java.util.Collections; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Map.Entry; 12 | 13 | import net.sf.flatpack.structure.ColumnMetaData; 14 | import net.sf.flatpack.util.FPConstants; 15 | 16 | /** 17 | * @author Benoit Xhenseval 18 | * 19 | */ 20 | public class MetaData { 21 | private List columnsNames; 22 | private Map columnIndexMap; 23 | private final Map xmlRecordElements; 24 | 25 | public MetaData(final List columnNames, final Map columnIndexMap) { 26 | this.columnsNames = Collections.unmodifiableList(columnNames); 27 | this.columnIndexMap = Collections.unmodifiableMap(columnIndexMap); 28 | this.xmlRecordElements = new HashMap(); 29 | } 30 | 31 | MetaData(final List columnNames, final Map columnIndexMap, final Map xmlRecordElements) { 32 | this.columnsNames = Collections.unmodifiableList(columnNames); 33 | this.columnIndexMap = columnIndexMap; 34 | this.xmlRecordElements = xmlRecordElements; 35 | } 36 | 37 | public List getColumnsNames() { 38 | return columnsNames; 39 | } 40 | 41 | public Map getColumnIndexMap() { 42 | return columnIndexMap; 43 | } 44 | 45 | public void setColumnIndexMap(final Map columnIndexMap) { 46 | this.columnIndexMap = columnIndexMap; 47 | } 48 | 49 | public void setColumnsNames(final List columnsNames) { 50 | this.columnsNames = Collections.unmodifiableList(columnsNames); 51 | } 52 | 53 | public boolean isAnyRecordFormatSpecified() { 54 | return xmlRecordElements != null && !xmlRecordElements.isEmpty(); 55 | } 56 | 57 | public Iterator> xmlRecordIterator() { 58 | return xmlRecordElements.entrySet().iterator(); 59 | } 60 | 61 | public List getListColumnsForRecord(final String key) { 62 | return xmlRecordElements.get(key).getColumns(); 63 | } 64 | 65 | public int getColumnIndex(final String key, final String columnName) { 66 | int idx = -1; 67 | if (key != null && !key.equals(FPConstants.DETAIL_ID) && !key.equals(FPConstants.COL_IDX)) { 68 | idx = xmlRecordElements.get(key).getColumnIndex(columnName); 69 | } else if (key == null || key.equals(FPConstants.DETAIL_ID)) { 70 | final Integer i = (Integer) columnIndexMap.get(columnName); 71 | if (i != null) { // happens when the col name does not exist in the 72 | // mapping 73 | idx = i.intValue(); 74 | } 75 | } 76 | return idx; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | final StringBuilder buf = new StringBuilder(); 82 | buf.append("Col Names:").append(columnsNames).append(System.lineSeparator()); 83 | buf.append("Col Index Map:").append(columnIndexMap).append(System.lineSeparator()); 84 | buf.append("XML Record Elements:").append(xmlRecordElements).append(System.lineSeparator()); 85 | return buf.toString(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /flatpack/src/site/style/maven-objectlabkit.css: -------------------------------------------------------------------------------- 1 | body, select, input, li { 2 | background: #ffffff; 3 | color: #002070; 4 | font-family: Verdana, Arial, Helvetica, sans-serif; 5 | font-size: 12px; 6 | } 7 | 8 | a img { 9 | border: 0; 10 | } 11 | 12 | a:link, a:visited { 13 | color: #0020d0; 14 | text-decoration: underline; 15 | } 16 | 17 | a:hover { 18 | color: #0000ff !important; 19 | } 20 | 21 | a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { 22 | background: url(../images/external.png) right center no-repeat; 23 | padding-right: 15px; 24 | } 25 | 26 | a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { 27 | background: url(../images/newwindow.png) right center no-repeat; 28 | padding-right: 18px; 29 | } 30 | 31 | h2 { 32 | padding: 2px 5px; 33 | border: 1px solid #c0c0c0; 34 | color: #002070; 35 | background-color: #eeeeee; 36 | font-weight: bold; 37 | font-size: 16px; 38 | } 39 | 40 | h3 { 41 | padding: 2px 5px; 42 | border: 1px solid #aaaaaa; 43 | color: #002070; 44 | background-color: #eeeeee; 45 | font-size: 14px; 46 | } 47 | 48 | p { 49 | line-height: 1.3em; 50 | font-size: small; 51 | } 52 | 53 | #breadcrumbs { 54 | background: url(../images/grayBar.jpg); 55 | border: 1px solid #c0c0c0; 56 | height: 17px; 57 | } 58 | 59 | #breadcrumbs a { 60 | font-size: 11px; 61 | font-weight: bold; 62 | margin: 0px 2px; 63 | text-decoration: none; 64 | } 65 | 66 | #leftColumn { 67 | border: 1px solid #999999; 68 | border-top: 0; 69 | border-left: 0; 70 | background: #eeeeee; 71 | } 72 | 73 | div#navcolumn { 74 | font-size: 12px; 75 | } 76 | 77 | div#navcolumn h5 { 78 | font-size: 12px; 79 | padding-top: 2px; 80 | } 81 | /* 82 | div#navcolumn li { 83 | background: #eeeeee !important; 84 | } 85 | */ 86 | div#navcolumn div a { 87 | color: #002070; 88 | font-size: 11px; 89 | text-decoration: none; 90 | } 91 | 92 | table.bodyTable th { 93 | color: #ffffff; 94 | background-color: #bbb; 95 | text-align: left; 96 | font-weight: bold; 97 | } 98 | 99 | table.bodyTable th { 100 | color: #ffffff; 101 | background-color: #bbb; 102 | text-align: left; 103 | font-weight: bold; 104 | } 105 | 106 | table.bodyTable a { 107 | text-decoration : none; 108 | } 109 | 110 | table.bodyTable tr.a { 111 | background-color: #ddd; 112 | text-decoration : none; 113 | } 114 | 115 | table.bodyTable tr.b { 116 | background-color: #eee; 117 | } 118 | 119 | .source { 120 | background: #ffffdd; 121 | border: 1px solid #999999; 122 | color: #000000; 123 | font-size: 12px !important; 124 | margin-left: 10px; 125 | margin-right: 10px; 126 | padding: 5px 5px 5px 7px; 127 | } 128 | 129 | 130 | .xright, #projectLogo img, #projectLogo span{ 131 | float:right; 132 | color: #0020a0; 133 | } 134 | 135 | #footer { 136 | padding: 10px; 137 | margin: 20px 0px 20px 0px; 138 | border-top: solid #ccc 1px; 139 | color: #333333; 140 | } 141 | 142 | .subsectionTitle { 143 | font-size: 13px; 144 | font-weight: bold; 145 | color: #666; 146 | } 147 | -------------------------------------------------------------------------------- /src/site/resources/style/maven-objectlabkit.css: -------------------------------------------------------------------------------- 1 | body, select, input, li { 2 | background: #ffffff; 3 | color: #002070; 4 | font-family: Verdana, Arial, Helvetica, sans-serif; 5 | font-size: 12px; 6 | } 7 | 8 | a img { 9 | border: 0; 10 | } 11 | 12 | a:link, a:visited { 13 | color: #0020d0; 14 | text-decoration: underline; 15 | } 16 | 17 | a:hover { 18 | color: #0000ff !important; 19 | } 20 | 21 | a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { 22 | background: url(../images/external.png) right center no-repeat; 23 | padding-right: 15px; 24 | } 25 | 26 | a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { 27 | background: url(../images/newwindow.png) right center no-repeat; 28 | padding-right: 18px; 29 | } 30 | 31 | h2 { 32 | padding: 2px 5px; 33 | border: 1px solid #c0c0c0; 34 | color: #002070; 35 | background-color: #eeeeee; 36 | font-weight: bold; 37 | font-size: 16px; 38 | } 39 | 40 | h3 { 41 | padding: 2px 5px; 42 | border: 1px solid #aaaaaa; 43 | color: #002070; 44 | background-color: #eeeeee; 45 | font-size: 14px; 46 | } 47 | 48 | p { 49 | line-height: 1.3em; 50 | font-size: small; 51 | } 52 | 53 | #breadcrumbs { 54 | background: url(../images/grayBar.jpg); 55 | border: 1px solid #c0c0c0; 56 | height: 17px; 57 | } 58 | 59 | #breadcrumbs a { 60 | font-size: 11px; 61 | font-weight: bold; 62 | margin: 0px 2px; 63 | text-decoration: none; 64 | } 65 | 66 | #leftColumn { 67 | border: 1px solid #999999; 68 | border-top: 0; 69 | border-left: 0; 70 | background: #eeeeee; 71 | } 72 | 73 | div#navcolumn { 74 | font-size: 12px; 75 | } 76 | 77 | div#navcolumn h5 { 78 | font-size: 12px; 79 | padding-top: 2px; 80 | } 81 | /* 82 | div#navcolumn li { 83 | background: #eeeeee !important; 84 | } 85 | */ 86 | div#navcolumn div a { 87 | color: #002070; 88 | font-size: 11px; 89 | text-decoration: none; 90 | } 91 | 92 | table.bodyTable th { 93 | color: #ffffff; 94 | background-color: #bbb; 95 | text-align: left; 96 | font-weight: bold; 97 | } 98 | 99 | table.bodyTable th { 100 | color: #ffffff; 101 | background-color: #bbb; 102 | text-align: left; 103 | font-weight: bold; 104 | } 105 | 106 | table.bodyTable a { 107 | text-decoration : none; 108 | } 109 | 110 | table.bodyTable tr.a { 111 | background-color: #ddd; 112 | text-decoration : none; 113 | } 114 | 115 | table.bodyTable tr.b { 116 | background-color: #eee; 117 | } 118 | 119 | .source { 120 | background: #ffffdd; 121 | border: 1px solid #999999; 122 | color: #000000; 123 | font-size: 12px !important; 124 | margin-left: 10px; 125 | margin-right: 10px; 126 | padding: 5px 5px 5px 7px; 127 | } 128 | 129 | 130 | .xright, #projectLogo img, #projectLogo span{ 131 | float:right; 132 | color: #0020a0; 133 | } 134 | 135 | #footer { 136 | padding: 10px; 137 | margin: 20px 0px 20px 0px; 138 | border-top: solid #ccc 1px; 139 | color: #333333; 140 | } 141 | 142 | .subsectionTitle { 143 | font-size: 13px; 144 | font-weight: bold; 145 | color: #666; 146 | } 147 | -------------------------------------------------------------------------------- /flatpack-excel/src/site/style/maven-objectlabkit.css: -------------------------------------------------------------------------------- 1 | body, select, input, li { 2 | background: #ffffff; 3 | color: #002070; 4 | font-family: Verdana, Arial, Helvetica, sans-serif; 5 | font-size: 12px; 6 | } 7 | 8 | a img { 9 | border: 0; 10 | } 11 | 12 | a:link, a:visited { 13 | color: #0020d0; 14 | text-decoration: underline; 15 | } 16 | 17 | a:hover { 18 | color: #0000ff !important; 19 | } 20 | 21 | a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { 22 | background: url(../images/external.png) right center no-repeat; 23 | padding-right: 15px; 24 | } 25 | 26 | a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { 27 | background: url(../images/newwindow.png) right center no-repeat; 28 | padding-right: 18px; 29 | } 30 | 31 | h2 { 32 | padding: 2px 5px; 33 | border: 1px solid #c0c0c0; 34 | color: #002070; 35 | background-color: #eeeeee; 36 | font-weight: bold; 37 | font-size: 16px; 38 | } 39 | 40 | h3 { 41 | padding: 2px 5px; 42 | border: 1px solid #aaaaaa; 43 | color: #002070; 44 | background-color: #eeeeee; 45 | font-size: 14px; 46 | } 47 | 48 | p { 49 | line-height: 1.3em; 50 | font-size: small; 51 | } 52 | 53 | #breadcrumbs { 54 | background: url(../images/grayBar.jpg); 55 | border: 1px solid #c0c0c0; 56 | height: 17px; 57 | } 58 | 59 | #breadcrumbs a { 60 | font-size: 11px; 61 | font-weight: bold; 62 | margin: 0px 2px; 63 | text-decoration: none; 64 | } 65 | 66 | #leftColumn { 67 | border: 1px solid #999999; 68 | border-top: 0; 69 | border-left: 0; 70 | background: #eeeeee; 71 | } 72 | 73 | div#navcolumn { 74 | font-size: 12px; 75 | } 76 | 77 | div#navcolumn h5 { 78 | font-size: 12px; 79 | padding-top: 2px; 80 | } 81 | /* 82 | div#navcolumn li { 83 | background: #eeeeee !important; 84 | } 85 | */ 86 | div#navcolumn div a { 87 | color: #002070; 88 | font-size: 11px; 89 | text-decoration: none; 90 | } 91 | 92 | table.bodyTable th { 93 | color: #ffffff; 94 | background-color: #bbb; 95 | text-align: left; 96 | font-weight: bold; 97 | } 98 | 99 | table.bodyTable th { 100 | color: #ffffff; 101 | background-color: #bbb; 102 | text-align: left; 103 | font-weight: bold; 104 | } 105 | 106 | table.bodyTable a { 107 | text-decoration : none; 108 | } 109 | 110 | table.bodyTable tr.a { 111 | background-color: #ddd; 112 | text-decoration : none; 113 | } 114 | 115 | table.bodyTable tr.b { 116 | background-color: #eee; 117 | } 118 | 119 | .source { 120 | background: #ffffdd; 121 | border: 1px solid #999999; 122 | color: #000000; 123 | font-size: 12px !important; 124 | margin-left: 10px; 125 | margin-right: 10px; 126 | padding: 5px 5px 5px 7px; 127 | } 128 | 129 | 130 | .xright, #projectLogo img, #projectLogo span{ 131 | float:right; 132 | color: #0020a0; 133 | } 134 | 135 | #footer { 136 | padding: 10px; 137 | margin: 20px 0px 20px 0px; 138 | border-top: solid #ccc 1px; 139 | color: #333333; 140 | } 141 | 142 | .subsectionTitle { 143 | font-size: 13px; 144 | font-weight: bold; 145 | color: #666; 146 | } 147 | -------------------------------------------------------------------------------- /flatpack-samples/src/site/style/maven-objectlabkit.css: -------------------------------------------------------------------------------- 1 | body, select, input, li { 2 | background: #ffffff; 3 | color: #002070; 4 | font-family: Verdana, Arial, Helvetica, sans-serif; 5 | font-size: 12px; 6 | } 7 | 8 | a img { 9 | border: 0; 10 | } 11 | 12 | a:link, a:visited { 13 | color: #0020d0; 14 | text-decoration: underline; 15 | } 16 | 17 | a:hover { 18 | color: #0000ff !important; 19 | } 20 | 21 | a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { 22 | background: url(../images/external.png) right center no-repeat; 23 | padding-right: 15px; 24 | } 25 | 26 | a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { 27 | background: url(../images/newwindow.png) right center no-repeat; 28 | padding-right: 18px; 29 | } 30 | 31 | h2 { 32 | padding: 2px 5px; 33 | border: 1px solid #c0c0c0; 34 | color: #002070; 35 | background-color: #eeeeee; 36 | font-weight: bold; 37 | font-size: 16px; 38 | } 39 | 40 | h3 { 41 | padding: 2px 5px; 42 | border: 1px solid #aaaaaa; 43 | color: #002070; 44 | background-color: #eeeeee; 45 | font-size: 14px; 46 | } 47 | 48 | p { 49 | line-height: 1.3em; 50 | font-size: small; 51 | } 52 | 53 | #breadcrumbs { 54 | background: url(../images/grayBar.jpg); 55 | border: 1px solid #c0c0c0; 56 | height: 17px; 57 | } 58 | 59 | #breadcrumbs a { 60 | font-size: 11px; 61 | font-weight: bold; 62 | margin: 0px 2px; 63 | text-decoration: none; 64 | } 65 | 66 | #leftColumn { 67 | border: 1px solid #999999; 68 | border-top: 0; 69 | border-left: 0; 70 | background: #eeeeee; 71 | } 72 | 73 | div#navcolumn { 74 | font-size: 12px; 75 | } 76 | 77 | div#navcolumn h5 { 78 | font-size: 12px; 79 | padding-top: 2px; 80 | } 81 | /* 82 | div#navcolumn li { 83 | background: #eeeeee !important; 84 | } 85 | */ 86 | div#navcolumn div a { 87 | color: #002070; 88 | font-size: 11px; 89 | text-decoration: none; 90 | } 91 | 92 | table.bodyTable th { 93 | color: #ffffff; 94 | background-color: #bbb; 95 | text-align: left; 96 | font-weight: bold; 97 | } 98 | 99 | table.bodyTable th { 100 | color: #ffffff; 101 | background-color: #bbb; 102 | text-align: left; 103 | font-weight: bold; 104 | } 105 | 106 | table.bodyTable a { 107 | text-decoration : none; 108 | } 109 | 110 | table.bodyTable tr.a { 111 | background-color: #ddd; 112 | text-decoration : none; 113 | } 114 | 115 | table.bodyTable tr.b { 116 | background-color: #eee; 117 | } 118 | 119 | .source { 120 | background: #ffffdd; 121 | border: 1px solid #999999; 122 | color: #000000; 123 | font-size: 12px !important; 124 | margin-left: 10px; 125 | margin-right: 10px; 126 | padding: 5px 5px 5px 7px; 127 | } 128 | 129 | 130 | .xright, #projectLogo img, #projectLogo span{ 131 | float:right; 132 | color: #0020a0; 133 | } 134 | 135 | #footer { 136 | padding: 10px; 137 | margin: 20px 0px 20px 0px; 138 | border-top: solid #ccc 1px; 139 | color: #333333; 140 | } 141 | 142 | .subsectionTitle { 143 | font-size: 13px; 144 | font-weight: bold; 145 | color: #666; 146 | } 147 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.fixedlengthheaderandtrailer; 2 | 3 | import java.io.FileReader; 4 | import java.util.Iterator; 5 | 6 | import net.sf.flatpack.DataError; 7 | import net.sf.flatpack.DataSet; 8 | import net.sf.flatpack.DefaultParserFactory; 9 | import net.sf.flatpack.Parser; 10 | 11 | /** 12 | * @author zepernick 13 | * 14 | * TODO To change the template for this generated type comment go to Window - 15 | * Preferences - Java - Code Style - Code Templates 16 | */ 17 | public class FixedLengthHeaderAndTrailer { 18 | public static void main(final String[] args) throws Exception { 19 | final String mapping = getDefaultMapping(); 20 | final String data = getDefaultDataFile(); 21 | call(mapping, data); 22 | 23 | } 24 | 25 | public static String getDefaultDataFile() { 26 | return "PEOPLE-FixedLengthWithHeaderTrailer.txt"; 27 | } 28 | 29 | public static String getDefaultMapping() { 30 | return "PEOPLE-FixedLengthWithHeaderTrailer.pzmap.xml"; 31 | } 32 | 33 | public static void call(final String mapping, final String data) throws Exception { 34 | Iterator errors = null; 35 | DataError dataError = null; 36 | final Parser pzparser = DefaultParserFactory.getInstance().newFixedLengthParser(new FileReader(mapping), new FileReader(data)); 37 | final DataSet ds = pzparser.parse(); 38 | 39 | while (ds.next()) { 40 | 41 | if (ds.isRecordID("header")) { 42 | System.out.println(">>>>found header"); 43 | System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("INDICATOR")); 44 | System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA")); 45 | System.out.println("==========================================================================="); 46 | continue; 47 | } 48 | 49 | if (ds.isRecordID("trailer")) { 50 | System.out.println(">>>>found trailer"); 51 | System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("INDICATOR")); 52 | System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA")); 53 | System.out.println("==========================================================================="); 54 | continue; 55 | } 56 | 57 | System.out.println("COLUMN NAME: FIRSTNAME VALUE: " + ds.getString("FIRSTNAME")); 58 | System.out.println("COLUMN NAME: LASTNAME VALUE: " + ds.getString("LASTNAME")); 59 | System.out.println("COLUMN NAME: ADDRESS VALUE: " + ds.getString("ADDRESS")); 60 | System.out.println("COLUMN NAME: CITY VALUE: " + ds.getString("CITY")); 61 | System.out.println("COLUMN NAME: STATE VALUE: " + ds.getString("STATE")); 62 | System.out.println("COLUMN NAME: ZIP VALUE: " + ds.getString("ZIP")); 63 | System.out.println("==========================================================================="); 64 | 65 | } 66 | 67 | if (ds.getErrors() != null && !ds.getErrors().isEmpty()) { 68 | errors = ds.getErrors().iterator(); 69 | 70 | while (errors.hasNext()) { 71 | dataError = (DataError) errors.next(); 72 | 73 | System.out.println("ERROR: " + dataError.getErrorDesc() + " LINE NUMBER: " + dataError.getLineNo()); 74 | } 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/delim/pipe/PipeParserTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.delim.pipe; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.io.Reader; 6 | import java.io.StringReader; 7 | 8 | import junit.framework.TestCase; 9 | import net.sf.flatpack.DataSet; 10 | import net.sf.flatpack.Parser; 11 | import net.sf.flatpack.brparse.BuffReaderParseFactory; 12 | 13 | /** 14 | * @author xhensevalb 15 | * 16 | */ 17 | public class PipeParserTest extends TestCase { 18 | /** 19 | */ 20 | public void testPipe() { 21 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"val1\"|\"val2\"|\"val3\""; 22 | 23 | final String[] expectedResult = { "val1", "val2", "val3" }; 24 | 25 | parseAndCheck(testCsv, expectedResult); 26 | } 27 | 28 | public void testPipeMultiline() { 29 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"val" + System.lineSeparator() + "1\"|\"val2\"|\"val3\""; 30 | 31 | final String[] expectedResult = { "val" + System.lineSeparator() + "1", "val2", "val3" }; 32 | parseAndCheck(testCsv, expectedResult); 33 | } 34 | 35 | public void testPipeMultilineAfterDelimiter() { 36 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"val1\"|\"" + System.lineSeparator() + "val2\"|\"val3\""; 37 | 38 | final String[] expectedResult = { "val1", System.lineSeparator() + "val2", "val3" }; 39 | parseAndCheck(testCsv, expectedResult); 40 | } 41 | 42 | public void testPipeMultilineDelimiterIsFirst() { 43 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"" + System.lineSeparator() + "val1\"|\"val2\"|\"val3\""; 44 | 45 | final String[] expectedResult = { System.lineSeparator() + "val1", "val2", "val3" }; 46 | 47 | parseAndCheck(testCsv, expectedResult); 48 | } 49 | 50 | public void testPipeMultilineDoubleLine() { 51 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"val" // 52 | + System.lineSeparator() + System.lineSeparator() + "1" + System.lineSeparator() + "2\"|\"val2\"|\"val3\""; 53 | 54 | final String[] expectedResult = { "val" + System.lineSeparator() + System.lineSeparator() + "1" + System.lineSeparator() + "2", "val2", 55 | "val3" }; 56 | 57 | parseAndCheck(testCsv, expectedResult); 58 | } 59 | 60 | public void testPipeMultilineEmpty() { 61 | final String testCsv = "\"col1\"|\"col2\"|\"col3\"" + System.lineSeparator() + "\"val" + System.lineSeparator() + "2\"|\"\"|\"\""; 62 | 63 | final String[] expectedResult = { "val" + System.lineSeparator() + "2", "", "" }; 64 | 65 | parseAndCheck(testCsv, expectedResult); 66 | } 67 | 68 | private void parseAndCheck(final String testCsv, final String[] expectedResult) { 69 | final Reader bis = new StringReader(testCsv); 70 | final Parser parser = BuffReaderParseFactory.getInstance().newDelimitedParser(bis, '|', '"'); 71 | final DataSet result = parser.parse(); 72 | 73 | // no errors should be in result, we should have 1 row with 7 columns 74 | // assertThat(result.getErrorCount()).isEqualTo(0); 75 | // assertThat(result.getRowCount()).isEqualTo(1); 76 | 77 | result.next(); 78 | assertThat(result.getColumns().length).isEqualTo(expectedResult.length); 79 | final String[] columns = result.getColumns(); 80 | 81 | for (int i = 0; i < expectedResult.length; ++i) { 82 | assertThat(expectedResult[i]).isEqualTo(result.getString(columns[i])); 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Appendium Ltd 6 | images/appendium_logo.jpg 7 | http://www.appendium.com 8 | 9 | 10 | ObjectLab Ltd 11 | images/objectlab_logo.jpg 12 | http://www.objectlab.co.uk/ 13 | 14 | 15 | 16 | 18 | 20 | 21 | 22 | 23 | org.apache.maven.skins 24 | maven-stylus-skin 25 | 1.2 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |

71 | 72 | Get FlatPack Java API For Flat Files at SourceForge.net. Fast, secure and Free Open Source software downloads 76 | 77 | 78 | ObjectLab Open Source News 80 | 81 |

82 |

83 |
84 | 86 | 89 |
90 | 91 | -------------------------------------------------------------------------------- /flatpack-samples/src/main/java/net/sf/flatpack/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java: -------------------------------------------------------------------------------- 1 | package net.sf.flatpack.examples.delimiteddynamiccolumnswitherrors; 2 | 3 | /* 4 | * Created on Dec 31, 2004 5 | * 6 | */ 7 | 8 | import java.io.File; 9 | import java.util.Iterator; 10 | 11 | import net.sf.flatpack.DataError; 12 | import net.sf.flatpack.DataSet; 13 | import net.sf.flatpack.DefaultParserFactory; 14 | import net.sf.flatpack.Parser; 15 | import net.sf.flatpack.ordering.OrderBy; 16 | import net.sf.flatpack.ordering.OrderColumn; 17 | 18 | /** 19 | * @author zepernick 20 | * 21 | * TODO To change the template for this generated type comment go to Window - 22 | * Preferences - Java - Code Style - Code Templates 23 | */ 24 | public class DelimitedWithPZMapErrors { 25 | public static void main(final String[] args) throws Exception { 26 | final String mapping = getDefaultMapping(); 27 | final String data = getDefaultDataFile(); 28 | call(mapping, data); 29 | 30 | } 31 | 32 | public static String getDefaultDataFile() { 33 | return "PEOPLE-CommaDelimitedWithQualifierAndHeaderTrailerRecError.txt"; 34 | } 35 | 36 | public static String getDefaultMapping() { 37 | return "PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml"; 38 | } 39 | 40 | public static void call(final String mapping, final String data) throws Exception { 41 | // delimited by a comma 42 | // text qualified by double quotes 43 | // ignore first record 44 | final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '"', true); 45 | final DataSet ds = pzparser.parse(); 46 | // re order the data set by last name 47 | final OrderBy orderby = new OrderBy(); 48 | orderby.addOrderColumn(new OrderColumn("CITY", false)); 49 | orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); 50 | ds.orderRows(orderby); 51 | 52 | final String[] colNames = ds.getColumns(); 53 | 54 | while (ds.next()) { 55 | 56 | if (ds.isRecordID("header")) { 57 | System.out.println(">>>>found header"); 58 | System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("RECORDINDICATOR")); 59 | System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA")); 60 | System.out.println("==========================================================================="); 61 | continue; 62 | } 63 | 64 | if (ds.isRecordID("trailer")) { 65 | System.out.println(">>>>found trailer"); 66 | System.out.println("COLUMN NAME: INDICATOR VALUE: " + ds.getString("RECORDINDICATOR")); 67 | System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA")); 68 | System.out.println("==========================================================================="); 69 | continue; 70 | } 71 | 72 | for (final String colName : colNames) { 73 | System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName)); 74 | } 75 | 76 | System.out.println("==========================================================================="); 77 | } 78 | 79 | System.out.println(">>>>>>ERRORS!!!"); 80 | final Iterator errors = ds.getErrors().iterator(); 81 | while (errors.hasNext()) { 82 | final DataError dataError = (DataError) errors.next(); 83 | 84 | System.out.println("ERROR: " + dataError.getErrorDesc() + " LINE NUMBER: " + dataError.getLineNo()); 85 | } 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /flatpack/src/test/java/net/sf/flatpack/parserutils/ParserUtilsLTrimTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006 Paul Zepernick 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software distributed 11 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | CONDITIONS OF ANY KIND, either express or implied. See the License for 13 | the specific language governing permissions and limitations under the License. 14 | */ 15 | package net.sf.flatpack.parserutils; 16 | 17 | import junit.framework.TestCase; 18 | import net.sf.flatpack.util.ParserUtils; 19 | 20 | /** 21 | * Tests the functionality of the left trim in the ParserUtils 22 | * 23 | * @author paul zepernick 24 | */ 25 | public class ParserUtilsLTrimTest extends TestCase { 26 | /** 27 | * Make sure all spaces are properly removed from the front of the String 28 | * 29 | */ 30 | public void testTrimLeadingSpaces() { 31 | final String testS = " RemoveAll SpacesFromMe"; 32 | assertEquals("RemoveAll SpacesFromMe", ParserUtils.lTrim(testS)); 33 | } 34 | 35 | /** 36 | * Make sure all spaces are properly removed from the front of the String 37 | * leaving the trailing spaces at the end 38 | * 39 | */ 40 | public void testTrimLeadingSpacesWithTrailingSpaces() { 41 | final String testS = " RemoveAll SpacesFromMe "; 42 | final String tResult = ParserUtils.lTrim(testS); 43 | assertEquals("RemoveAll SpacesFromMe ", tResult); 44 | } 45 | 46 | /** 47 | * Make sure all TAB chars are properly removed from the front of the String 48 | * leaving the trailing spaces at the end 49 | * 50 | */ 51 | public void testTrimLeadingTabs() { 52 | final String testS = "\t\t\tRemoveAll SpacesFromMe "; 53 | final String tResult = ParserUtils.lTrim(testS); 54 | assertEquals("RemoveAll SpacesFromMe ", tResult); 55 | } 56 | 57 | /** 58 | * Make sure all TAB chars are properly removed from the front of the String 59 | * leaving the trailing spaces at the end 60 | * 61 | */ 62 | public void testKeepLeadingTabs() { 63 | final String testS = " \t\t\tRemoveAll SpacesFromMe "; 64 | final String tResult = ParserUtils.lTrimKeepTabs(testS); 65 | assertEquals("\t\t\tRemoveAll SpacesFromMe ", tResult); 66 | } 67 | 68 | /** 69 | * Ensure that spaces and tabs in the middle of the string will 70 | * not be removed. 71 | */ 72 | public void testWithTabsInMiddleAndEnd() { 73 | assertEquals("RemoveAll \tSpaces \t\t", ParserUtils.lTrim("\t \t RemoveAll \tSpaces \t\t")); 74 | assertEquals("\t \t RemoveAll \tSpaces \t\t ", ParserUtils.lTrimKeepTabs(" \t \t RemoveAll \tSpaces \t\t ")); 75 | assertEquals("\t \t RemoveAll \tSpaces \t\t", ParserUtils.lTrimKeepTabs("\t \t RemoveAll \tSpaces \t\t")); 76 | } 77 | 78 | /** 79 | * Make sure all spaces are properly removed from the end of the String 80 | * 81 | */ 82 | public void testTrimTrailingSpaces() { 83 | final String testS = " RemoveAll trailing SpacesFromMe "; 84 | assertEquals(" RemoveAll trailing SpacesFromMe", ParserUtils.rTrim(testS)); 85 | 86 | assertEquals("", ParserUtils.rTrim(" ")); 87 | assertEquals("test", ParserUtils.rTrim("test")); 88 | } 89 | 90 | public static void main(final String[] args) { 91 | junit.textui.TestRunner.run(ParserUtilsLTrimTest.class); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/site/xdoc/parsing.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Parsing Examples 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |

We thought that a few explicit examples would be good...The idea is to make our parsing extremely robust and flexible.

24 | 25 | 26 |

Our library is very flexible and lets you define both the delimiter character and the qualifier. The qualifier is character that may 27 | surround your element. Typically this would be a " in Excel, but Excel may not surround every element with it. Here are some examples:

28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |
DelimiterQualifierInputOutput
,"a,b,c3 elements: "a" "b" "c"
,""a,b,c"1 element: "a,b,c"
,""a,b","c"2 elements: "a,b" "c"
," a,b,c3 elements: "a" "b" "c"
,"a",b,c"1 element: a",b,c"
,""test1",test2,"0.00","another, element here",lastone5 elements: "test1" "test2" "0.00" "another, element here" "lastone"
,'a,b,c3 elements: "a" "b" "c"
,'"a,b,c"3 elements: ""a" "b" "c""
,'"a,b","c"2 elements: ""a,b"" ""c""
,' a,b,c3 elements: "a" "b" "c"
,'a",b,c"3 elements: "a"" "b" "c""
,'"test1",test2,"0.00","another, element here",lastone6 elements: ""test1"" "test2" ""0.00"" ""another" "element here\"" "lastone"
105 | 106 |
107 | 108 | 109 | 110 | 111 |
112 | 113 | 114 |
--------------------------------------------------------------------------------