You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(112) |
Nov
(44) |
Dec
(49) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(14) |
Feb
(12) |
Mar
(12) |
Apr
(12) |
May
(6) |
Jun
(11) |
Jul
(10) |
Aug
(6) |
Sep
(17) |
Oct
(3) |
Nov
(22) |
Dec
|
2008 |
Jan
(3) |
Feb
(7) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
(6) |
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
(1) |
Mar
(9) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(2) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
(3) |
Feb
|
Mar
(2) |
Apr
(8) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <zep...@us...> - 2006-12-15 02:07:56
|
Revision: 215 http://svn.sourceforge.net/pzfilereader/?rev=215&view=rev Author: zepernick Date: 2006-12-14 18:07:56 -0800 (Thu, 14 Dec 2006) Log Message: ----------- first attempt at reading files with BufferedReader left open while the file is being looped through. This is incomplete Benoit, but maybe you can take a peak and see what you think about the direction this is heading. Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderPZParseFactory.java Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZDataSet.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZDataSet.java 2006-12-15 02:07:56 UTC (rev 215) @@ -0,0 +1,51 @@ +package net.sf.pzfilereader.brparse; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +import net.sf.pzfilereader.DefaultDataSet; +import net.sf.pzfilereader.structure.Row; + +public class BuffReaderDelimPZDataSet extends DefaultDataSet{ + private BuffReaderDelimPZParser brpzparser; + + public BuffReaderDelimPZDataSet(final Map columnMD2, BuffReaderDelimPZParser brpzparser) { + super(columnMD2); + //register the parser with the dataset so we can fetch rows from + //the bufferedreader as needed + this.brpzparser = brpzparser; + } + + public boolean next() { + try { + final Row r = brpzparser.buildRow(this); + + if (r == null) { + setPointer(-1); + return false; + } + + //make sure we have some MD + if (getColumnMD() == null) { + //create a new map so the user cannot change the internal + //DataSet representation of the MD through the parser + setColumnMD(new LinkedHashMap(brpzparser.getColumnMD())); + } + + getRows().clear(); + addRow(r); + + setPointer(0); + + return true; + + } catch(IOException ex) { + //TODO real logging here + ex.printStackTrace(); + } + + return false; + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderDelimPZParser.java 2006-12-15 02:07:56 UTC (rev 215) @@ -0,0 +1,158 @@ +package net.sf.pzfilereader.brparse; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultDataSet; +import net.sf.pzfilereader.DelimiterPZParser; +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +public class BuffReaderDelimPZParser extends DelimiterPZParser { + private BufferedReader br; + private InputStreamReader isr; + private boolean processedFirst = false; + + public BuffReaderDelimPZParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { + super(dataSource, delimiter, qualifier, ignoreFirstRecord); + } + + public BuffReaderDelimPZParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, + final char qualifier, final boolean ignoreFirstRecord) { + super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + } + + public BuffReaderDelimPZParser(final File dataSource, final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { + super(dataSource, delimiter, qualifier, ignoreFirstRecord); + } + + public BuffReaderDelimPZParser(final InputStream dataSourceStream, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { + super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + } + + + public DataSet doParse() { + final DataSet ds = new BuffReaderDelimPZDataSet(getColumnMD(), this); + try { + //gather the conversion properties + ds.setPZConvertProps(ParserUtils.loadConvertProperties()); + + if (getDataSourceStream() == null) { + setDataSourceStream(ParserUtils.createInputStream(getDataSource())); + } + + isr = new InputStreamReader(getDataSourceStream()); + br = new BufferedReader(isr); + + return ds; + + } catch(IOException ex) { + ex.printStackTrace(); + } + + return null; + } + + /** + * Reads in the next record on the file and return a row + * + * @param ds + * @return Row + * @throws IOException + */ + public Row buildRow(final DefaultDataSet ds) throws IOException{ + /** loop through each line in the file */ + while (true) { + String line = fetchNextRecord(br, getQualifier(), getDelimiter()); + + if (line == null) { + return null; + } + + // check to see if the user has elected to skip the first record + if (!processedFirst && isIgnoreFirstRecord()) { + processedFirst = true; + continue; + } else if (!processedFirst && shouldCreateMDFromFile()) { + processedFirst = true; + setColumnMD(ParserUtils.getColumnMDFromFile(line, getDelimiter(), getQualifier())); + continue; + } + + //TODO + //seems like we may want to try doing something like this. I have my reservations because + //it is possible that we don't get a "detail" id and this might generate NPE + //is it going to create too much overhead to do a null check here as well??? + //final int intialSize = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, getColumnMD()).size(); + // column values + final List columns = ParserUtils.splitLine(line, getDelimiter(), getQualifier(), PZConstants.SPLITLINE_SIZE_INIT); + final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); + final List cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); + final int columnCount = cmds.size(); + // DEBUG + + // Incorrect record length on line log the error. Line + // will not be included in the dataset + if (columns.size() > columnCount) { + // log the error + addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2); + continue; + } else if (columns.size() < columnCount) { + if (isHandlingShortLines()) { + // We can pad this line out + while (columns.size() < columnCount) { + columns.add(""); + } + + // log a warning + addError(ds, "PADDED LINE TO CORRECT NUMBER OF COLUMNS", getLineCount(), 1); + + } else { + addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2); + continue; + } + } + + final Row row = new Row(); + row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try + // to limit the memory use + row.setCols(columns); + row.setRowNumber(getLineCount()); + + return row; + } + } + + /** + * Closes out the file readers + * + *@throws IOException + */ + public void close() throws IOException{ + if (br != null) { + br.close(); + } + if (isr != null) { + isr.close(); + } + } + + /** + * Returns the meta data describing the columns + */ + public Map getColumnMD() { + return super.getColumnMD(); + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderPZParseFactory.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderPZParseFactory.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/brparse/BuffReaderPZParseFactory.java 2006-12-15 02:07:56 UTC (rev 215) @@ -0,0 +1,121 @@ +package net.sf.pzfilereader.brparse; + +import java.io.File; +import java.io.InputStream; +import java.sql.Connection; + +import net.sf.pzfilereader.PZParser; +import net.sf.pzfilereader.PZParserFactory; + +/** + * Provides a PZParser which obtains records directly from + * a BufferedReader as an alternative to reading the + * entire file into memory. + * + * @author Paul Zepernick + */ +public class BuffReaderPZParseFactory implements PZParserFactory{ + private static final BuffReaderPZParseFactory INSTANCE = new BuffReaderPZParseFactory(); + + public static PZParserFactory getInstance() { + return INSTANCE; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, + * java.io.File, java.lang.String) + */ + public PZParser newFixedLengthParser(final Connection con, final File dataSource, final String dataDefinition) { + //return new DBFixedLengthPZParser(con, dataSource, dataDefinition); + return null; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, + * java.io.InputStream, java.lang.String) + */ + public PZParser newFixedLengthParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition) { + //return new DBFixedLengthPZParser(con, dataSourceStream, dataDefinition); + return null; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, + * java.io.File) + */ + public PZParser newFixedLengthParser(final File pzmapXML, final File dataSource) { + // return new FixedLengthPZParser(pzmapXML, dataSource); + return null; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * java.io.InputStream) + */ + public PZParser newFixedLengthParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) { + // return new FixedLengthPZParser(pzmapXMLStream, dataSourceStream); + return null; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.sql.Connection, + * java.io.InputStream, java.lang.String, char, char, boolean) + */ + public PZParser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, + final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { + //return new BuffReaderDelimPZParser(con, dataSourceStream, dataDefinition, delimiter, qualifier, ignoreFirstRecord); + return null; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, + * java.io.File, char, char, boolean) + */ + public PZParser newDelimitedParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { + return new BuffReaderDelimPZParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * java.io.InputStream, char, char, boolean) + */ + public PZParser newDelimitedParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, + final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { + return new BuffReaderDelimPZParser(pzmapXMLStream, dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, char, + * char) + */ + public PZParser newDelimitedParser(final File dataSource, final char delimiter, final char qualifier) { + return new BuffReaderDelimPZParser(dataSource, delimiter, qualifier, false); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * char, char) + */ + public PZParser newDelimitedParser(final InputStream dataSourceStream, final char delimiter, final char qualifier) { + return new BuffReaderDelimPZParser(dataSourceStream, delimiter, qualifier, false); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-12-15 01:59:57
|
Revision: 214 http://svn.sourceforge.net/pzfilereader/?rev=214&view=rev Author: zepernick Date: 2006-12-14 17:59:56 -0800 (Thu, 14 Dec 2006) Log Message: ----------- added some protected methods for more control by extending classes. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-12-15 01:59:01 UTC (rev 213) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-12-15 01:59:56 UTC (rev 214) @@ -439,8 +439,27 @@ this.pzConvertProps = props; } - void setColumnMD(final Map columnMD) { + protected void setColumnMD(final Map columnMD) { this.columnMD = columnMD; } + + /** + * Returns the column meta data assoicated with + * this DataSet + * + * @return Map + */ + protected Map getColumnMD() { + return this.columnMD; + } + /** + * @param pointer the pointer to set + */ + protected void setPointer(int pointer) { + this.pointer = pointer; + } + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-12-15 01:59:02
|
Revision: 213 http://svn.sourceforge.net/pzfilereader/?rev=213&view=rev Author: zepernick Date: 2006-12-14 17:59:01 -0800 (Thu, 14 Dec 2006) Log Message: ----------- added a method to fetch the next record from a given BufferedReader. Utilized this in the new BufferedReader parsers, and coule be usefull for future parser implementations. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-12-15 00:26:53 UTC (rev 212) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-12-15 01:59:01 UTC (rev 213) @@ -56,6 +56,8 @@ private char qualifier = 0; private boolean ignoreFirstRecord = false; + + private int lineCount = 0; public AbstractDelimiterPZParser(final InputStream dataSourceStream, final String dataDefinition, final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { @@ -83,6 +85,7 @@ public DataSet doParse() { try { + lineCount = 0; if (getDataSourceStream() != null) { return doDelimitedFile(getDataSourceStream(), getDelimiter(), getQualifier(), isIgnoreFirstRecord(), shouldCreateMDFromFile()); @@ -137,6 +140,10 @@ this.qualifier = qualifier; } + protected int getLineCount() { + return lineCount; + } + /* * This is the new version of doDelimitedFile using InputStrem instead of * File. This is more flexible especially it is working with WebStart. @@ -145,7 +152,7 @@ * mappings, and SQL table mappings */ private DataSet doDelimitedFile(final InputStream dataSource, final char delimiter, final char qualifier, - final boolean ignoreFirstRecord, final boolean createMDFromFile) throws IOException, Exception { + final boolean ignoreFirstRecord, final boolean createMDFromFile) throws IOException { if (dataSource == null) { throw new NullPointerException("dataSource is null"); } @@ -160,25 +167,13 @@ // get the total column count // columnCount = columnMD.size(); - /** Read in the flat file */ - // fr = new FileReader(dataSource.getAbsolutePath()); isr = new InputStreamReader(dataSource); br = new BufferedReader(isr); boolean processedFirst = false; - boolean processingMultiLine = false; - int lineCount = 0; - String lineData = ""; /** loop through each line in the file */ String line = null; - while ((line = br.readLine()) != null) { - lineCount++; - /** empty line skip past it */ - final String trimmed = line.trim(); - if (!processingMultiLine && trimmed.length() == 0) { - continue; - } - + while ((line = fetchNextRecord(br, qualifier, delimiter)) != null) { // check to see if the user has elected to skip the first record if (!processedFirst && ignoreFirstRecord) { processedFirst = true; @@ -190,96 +185,13 @@ continue; } - // ******************************************************** - // new functionality as of 2.1.0 check to see if we have - // any line breaks in the middle of the record, this will only - // be checked if we have specified a delimiter - // ******************************************************** - final char[] chrArry = trimmed.toCharArray(); - if (!processingMultiLine && delimiter > 0) { - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - } - - // check to see if we have reached the end of the linebreak in - // the record - - final String trimmedLineData = lineData.trim(); - if (processingMultiLine && trimmedLineData.length() > 0) { - // need to do one last check here. it is possible that the " - // could be part of the data - // excel will escape these with another quote; here is some - // data "" This would indicate - // there is more to the multiline - if (trimmed.charAt(trimmed.length() - 1) == qualifier && !trimmed.endsWith("" + qualifier + qualifier)) { - // it is safe to assume we have reached the end of the - // line break - processingMultiLine = false; - if (trimmedLineData.length() > 0) { // + would always be - // true surely.... - lineData += "\r\n"; - } - lineData += line; - } else { - // check to see if this is the last line of the record - // looking for a qualifier followed by a delimiter - if (trimmedLineData.length() > 0) { // + here again, - // this should - // always be true... - lineData += "\r\n"; - } - lineData += line; - boolean qualiFound = false; - for (int i = 0; i < chrArry.length; i++) { - if (qualiFound) { - if (chrArry[i] == ' ') { - continue; - } else { - // not a space, if this char is the - // delimiter, then we have reached the end - // of - // the record - if (chrArry[i] == delimiter) { - // processingMultiLine = false; - // fix put in, setting to false caused - // bug when processing multiple - // multi-line - // columns on the same record - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - break; - } - qualiFound = false; - continue; - } - } else if (chrArry[i] == qualifier) { - qualiFound = true; - } - } - // check to see if we are still in multi line mode, if - // so grab the next line - if (processingMultiLine) { - continue; - } - } - } else { - // throw the line into lineData var. - lineData += line; - if (processingMultiLine) { - continue; // if we are working on a multiline rec, get - // the data on the next line - } - } - // ******************************************************************** - // end record line break logic - // ******************************************************************** - - //TODO + //TODO //seems like we may want to try doing something like this. I have my reservations because //it is possible that we don't get a "detail" id and this might generate NPE //is it going to create too much overhead to do a null check here as well??? //final int intialSize = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, getColumnMD()).size(); // column values - final List columns = ParserUtils.splitLine(lineData, delimiter, qualifier, PZConstants.SPLITLINE_SIZE_INIT); - lineData = ""; + final List columns = ParserUtils.splitLine(line, delimiter, qualifier, PZConstants.SPLITLINE_SIZE_INIT); final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); final List cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); final int columnCount = cmds.size(); @@ -325,4 +237,119 @@ } return ds; } + + /** + * Reads a record from a delimited file. This will account for records which + * could span multiple lines. + * NULL will be returned when the end of the file is reached + * + * @param br + * Open reader being used to read through the file + * @return String + * Record from delimited file + * + */ + protected String fetchNextRecord(final BufferedReader br, final char qualifier, + final char delimiter) throws IOException{ + String line = null; + String lineData = ""; + boolean processingMultiLine = false; + + while ((line = br.readLine()) != null) { + lineCount++; + /** empty line skip past it */ + final String trimmed = line.trim(); + if (!processingMultiLine && trimmed.length() == 0) { + continue; + } + + // ******************************************************** + // new functionality as of 2.1.0 check to see if we have + // any line breaks in the middle of the record, this will only + // be checked if we have specified a delimiter + // ******************************************************** + final char[] chrArry = trimmed.toCharArray(); + if (!processingMultiLine && delimiter > 0) { + processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); + } + + // check to see if we have reached the end of the linebreak in + // the record + + final String trimmedLineData = lineData.trim(); + if (processingMultiLine && trimmedLineData.length() > 0) { + // need to do one last check here. it is possible that the " + // could be part of the data + // excel will escape these with another quote; here is some + // data "" This would indicate + // there is more to the multiline + if (trimmed.charAt(trimmed.length() - 1) == qualifier && !trimmed.endsWith("" + qualifier + qualifier)) { + // it is safe to assume we have reached the end of the + // line break + processingMultiLine = false; + if (trimmedLineData.length() > 0) { // + would always be + // true surely.... + lineData += "\r\n"; + } + lineData += line; + } else { + // check to see if this is the last line of the record + // looking for a qualifier followed by a delimiter + if (trimmedLineData.length() > 0) { // + here again, + // this should + // always be true... + lineData += "\r\n"; + } + lineData += line; + boolean qualiFound = false; + for (int i = 0; i < chrArry.length; i++) { + if (qualiFound) { + if (chrArry[i] == ' ') { + continue; + } else { + // not a space, if this char is the + // delimiter, then we have reached the end + // of + // the record + if (chrArry[i] == delimiter) { + // processingMultiLine = false; + // fix put in, setting to false caused + // bug when processing multiple + // multi-line + // columns on the same record + processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); + break; + } + qualiFound = false; + continue; + } + } else if (chrArry[i] == qualifier) { + qualiFound = true; + } + } + // check to see if we are still in multi line mode, if + // so grab the next line + if (processingMultiLine) { + continue; + } + } + } else { + // throw the line into lineData var. + lineData += line; + if (processingMultiLine) { + continue; // if we are working on a multiline rec, get + // the data on the next line + } + } + + break; + } + + if (line == null && lineData.length() == 0) { + //eof + return null; + } + + return lineData; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-12-15 00:26:52
|
Revision: 212 http://svn.sourceforge.net/pzfilereader/?rev=212&view=rev Author: zepernick Date: 2006-12-14 16:26:53 -0800 (Thu, 14 Dec 2006) Log Message: ----------- added to parse() javadoc comment Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-12-15 00:23:46 UTC (rev 211) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-12-15 00:26:53 UTC (rev 212) @@ -42,7 +42,8 @@ public interface PZParser { /** - * Start the parsing + * Start the parsing. Will return "null" if the + * parse fails and the DataSet cannot be created * * @return the data set resulting from parsing */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-12-15 00:23:46
|
Revision: 211 http://svn.sourceforge.net/pzfilereader/?rev=211&view=rev Author: zepernick Date: 2006-12-14 16:23:46 -0800 (Thu, 14 Dec 2006) Log Message: ----------- cleaned up exception handling. Got rid of throws Exception Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-12-12 12:55:58 UTC (rev 210) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-12-15 00:23:46 UTC (rev 211) @@ -398,7 +398,7 @@ * @exception Exception * @return ArrayList - ColumnMetaData */ - public static Map getColumnMDFromFile(final String line, final char delimiter, final char qualifier) throws Exception { + public static Map getColumnMDFromFile(final String line, final char delimiter, final char qualifier) { List lineData = null; final List results = new ArrayList(); final Map columnMD = new LinkedHashMap(); @@ -424,10 +424,12 @@ * @param theFile * @param delimiter * @param qualifier - * @exception Exception + * @exception FileNotFoundException + * @exception IOException * @return ArrayList - ColumnMetaData */ - public static List getColumnMDFromFile(final File theFile, final String delimiter, final String qualifier) throws Exception { + public static List getColumnMDFromFile(final File theFile, final String delimiter, + final String qualifier) throws IOException{ BufferedReader br = null; FileReader fr = null; String line = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-12-12 12:55:58
|
Revision: 210 http://svn.sourceforge.net/pzfilereader/?rev=210&view=rev Author: benoitx Date: 2006-12-12 04:55:58 -0800 (Tue, 12 Dec 2006) Log Message: ----------- Add the template so issues="XXXX" can be used for the SF issues/requests in changes.xml Modified Paths: -------------- trunk/common-build/project.properties Modified: trunk/common-build/project.properties =================================================================== --- trunk/common-build/project.properties 2006-11-27 16:06:49 UTC (rev 209) +++ trunk/common-build/project.properties 2006-12-12 12:55:58 UTC (rev 210) @@ -102,3 +102,4 @@ maven.multiproject.navigation=independent maven.repo.remote=http://repo1.maven.org/maven,http://people.apache.org/repo/m1-snapshot-repository/ +maven.changes.issue.template=http://sourceforge.net/support/tracker.php?aid=%ISSUE% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-27 16:06:57
|
Revision: 209 http://svn.sourceforge.net/pzfilereader/?rev=209&view=rev Author: zepernick Date: 2006-11-27 08:06:49 -0800 (Mon, 27 Nov 2006) Log Message: ----------- more efficient check for unescaped qualifier contained within a qualified element. This new change avoids substring and left trim per Benoit's suggestion. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-27 13:47:01 UTC (rev 208) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-27 16:06:49 UTC (rev 209) @@ -164,20 +164,29 @@ } else { endBlock = i + 1; } - } - //try to first look ahead 1 char. If we have a match on the delimiter it will drop to the else - //otherwise do one last check to make sure there is no space between the delimiter and - //the qualifer. This looks a little sloppy, but I am trying to avoid the left trim, and substring if - //possible. - // "a","b","c" should not call the lTrimKeepTabs - // "a", "b", "c" will use the lTrimKeepTabs to remove the space between the delimiter and qualifer - else if (i + 1 < size && delimiter != ' ' && - ((trimmedLine.charAt(i + 1) != ' ' && trimmedLine.charAt(i + 1) != delimiter) || - lTrimKeepTabs(trimmedLine.substring(i + 1)).charAt(0) != delimiter)) { - previousChar = currentChar; - endBlock = i + 1; - continue; } else { + if (i + 1 < size && delimiter != ' ') { + //this is used to allow unescaped qualifiers to be contained within the element + //do not run this check is a space is being used as a delimiter + //we don't want to trim the delimiter off + //loop until we find a char that is not a space, or we reach the end of the line. + int start = i + 1; + char charToCheck = trimmedLine.charAt(start); + while (charToCheck == ' ') { + start ++; + if (start == size) { + break; + } + charToCheck = trimmedLine.charAt(start); + } + + if (charToCheck != delimiter) { + previousChar = currentChar; + endBlock = i + 1; + continue; + } + + } insideQualifier = false; blockWasInQualifier = true; endBlock = i; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-27 13:47:06
|
Revision: 208 http://svn.sourceforge.net/pzfilereader/?rev=208&view=rev Author: zepernick Date: 2006-11-27 05:47:01 -0800 (Mon, 27 Nov 2006) Log Message: ----------- added to the comment about the lTrimKeepTabs Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-27 13:27:43 UTC (rev 207) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-27 13:47:01 UTC (rev 208) @@ -169,6 +169,8 @@ //otherwise do one last check to make sure there is no space between the delimiter and //the qualifer. This looks a little sloppy, but I am trying to avoid the left trim, and substring if //possible. + // "a","b","c" should not call the lTrimKeepTabs + // "a", "b", "c" will use the lTrimKeepTabs to remove the space between the delimiter and qualifer else if (i + 1 < size && delimiter != ' ' && ((trimmedLine.charAt(i + 1) != ' ' && trimmedLine.charAt(i + 1) != delimiter) || lTrimKeepTabs(trimmedLine.substring(i + 1)).charAt(0) != delimiter)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-27 13:27:45
|
Revision: 207 http://svn.sourceforge.net/pzfilereader/?rev=207&view=rev Author: zepernick Date: 2006-11-27 05:27:43 -0800 (Mon, 27 Nov 2006) Log Message: ----------- renamed IDataSet to DataSet Modified Paths: -------------- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/lowlevelparse/LowLevelParse.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java 2006-11-27 13:27:43 UTC (rev 207) @@ -8,7 +8,7 @@ import java.io.File; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -38,7 +38,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mapFile, dataFile, ',', '\"', true); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); while (ds.next()) { if (ds.isRecordID("header")) { Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java 2006-11-27 13:27:43 UTC (rev 207) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /* @@ -53,7 +53,7 @@ final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(filename), ',', '"'); long timeStarted = System.currentTimeMillis(); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); long timeFinished = System.currentTimeMillis(); String timeMessage = ""; Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java 2006-11-27 13:27:43 UTC (rev 207) @@ -12,7 +12,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -33,7 +33,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser( new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"'); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name orderby = new OrderBy(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java 2006-11-27 13:27:43 UTC (rev 207) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -44,7 +44,7 @@ OrderBy orderby = null; final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '"', true); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name orderby = new OrderBy(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java 2006-11-27 13:27:43 UTC (rev 207) @@ -11,7 +11,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -44,7 +44,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '"', true); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name final OrderBy orderby = new OrderBy(); orderby.addOrderColumn(new OrderColumn("CITY", false)); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java 2006-11-27 13:27:43 UTC (rev 207) @@ -10,7 +10,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -44,7 +44,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '"', true); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name final OrderBy orderby = new OrderBy(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java 2006-11-27 13:27:43 UTC (rev 207) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -37,7 +37,7 @@ public static void call(String mapping, String data) throws Exception { final PZParser pzparser = DefaultPZParserFactory.getInstance().newFixedLengthParser( new File(mapping), new File(data)); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); final String[] colNames = ds.getColumns(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java 2006-11-27 13:27:43 UTC (rev 207) @@ -11,7 +11,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -41,7 +41,7 @@ DataError dataError = null; final PZParser pzparser = DefaultPZParserFactory.getInstance().newFixedLengthParser(new File(mapping), new File(data)); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); while (ds.next()) { Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp 2006-11-27 13:27:43 UTC (rev 207) @@ -9,39 +9,39 @@ </head> <% - OrderBy order = null; - try{ - - File mappingFile = null; - File txtFile = null; - String appDirectory = null; - - //find out where this application is installed - appDirectory = getServletContext().getRealPath(""); - - mappingFile = new File (appDirectory + "/PEOPLE.pzmap.xml"); - txtFile = new File (appDirectory + "/PEOPLE.txt"); - - //read in the file - final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mappingFile, - txtFile, ',', 0, false) ; - final IDataSet ds = pzparser.parse(); - - - //check to see if there is a paramter in the request that is telling us what column to sort by - if (request.getParameter("orderby") != null && - request.getParameter("orderby").trim().length() > 0){ - - //sort the file by what was passed in the request - order = new OrderBy(); - order.addOrderColumn(new OrderColumn(request.getParameter("orderby"),false)); //set boolean to true for DESC sort - ds.orderRows(order); - - } - - }catch(Exception ex){ - out.println("Error: " + ex); - } + OrderBy order = null; + try{ + + File mappingFile = null; + File txtFile = null; + String appDirectory = null; + + //find out where this application is installed + appDirectory = getServletContext().getRealPath(""); + + mappingFile = new File (appDirectory + "/PEOPLE.pzmap.xml"); + txtFile = new File (appDirectory + "/PEOPLE.txt"); + + //read in the file + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mappingFile, + txtFile, ',', 0, false) ; + final DataSet ds = pzparser.parse(); + + + //check to see if there is a paramter in the request that is telling us what column to sort by + if (request.getParameter("orderby") != null && + request.getParameter("orderby").trim().length() > 0){ + + //sort the file by what was passed in the request + order = new OrderBy(); + order.addOrderColumn(new OrderColumn(request.getParameter("orderby"),false)); //set boolean to true for DESC sort + ds.orderRows(order); + + } + + }catch(Exception ex){ + out.println("Error: " + ex); + } %> <body> <table border="1"> Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/lowlevelparse/LowLevelParse.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/lowlevelparse/LowLevelParse.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/lowlevelparse/LowLevelParse.java 2006-11-27 13:27:43 UTC (rev 207) @@ -52,7 +52,7 @@ // text qualifier. The text qualifier is optional, it can be // null // or empty - elements = ParserUtils.splitLine(line, ',', '"'); + elements = ParserUtils.splitLine(line, ',', '"', 10); for (int i = 0; i < elements.size(); i++) { System.out.println("Column " + i + ": " + (String) elements.get(i)); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java 2006-11-27 13:27:43 UTC (rev 207) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -40,7 +40,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(data), ',', '\"'); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); final String[] colNames = ds.getColumns(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java 2006-11-27 13:22:39 UTC (rev 206) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java 2006-11-27 13:27:43 UTC (rev 207) @@ -10,7 +10,7 @@ import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -43,7 +43,7 @@ // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '\"', true); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // demonstrates the casting abilities of PZFileReader while (ds.next()) { System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-27 13:22:41
|
Revision: 206 http://svn.sourceforge.net/pzfilereader/?rev=206&view=rev Author: zepernick Date: 2006-11-27 05:22:39 -0800 (Mon, 27 Nov 2006) Log Message: ----------- renamed IDataSet to DataSet Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFileTest.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimitedTest.java Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-27 13:22:39 UTC (rev 206) @@ -81,7 +81,7 @@ this.ignoreFirstRecord = ignoreFirstRecord; } - public IDataSet doParse() { + public DataSet doParse() { try { if (getDataSourceStream() != null) { return doDelimitedFile(getDataSourceStream(), getDelimiter(), getQualifier(), isIgnoreFirstRecord(), @@ -144,7 +144,7 @@ * puts together the dataset for a DELIMITED file. This is used for PZ XML * mappings, and SQL table mappings */ - private IDataSet doDelimitedFile(final InputStream dataSource, final char delimiter, final char qualifier, + private DataSet doDelimitedFile(final InputStream dataSource, final char delimiter, final char qualifier, final boolean ignoreFirstRecord, final boolean createMDFromFile) throws IOException, Exception { if (dataSource == null) { throw new NullPointerException("dataSource is null"); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-11-27 13:22:39 UTC (rev 206) @@ -70,7 +70,7 @@ super(dataSourceStream); } - public IDataSet doParse() { + public DataSet doParse() { try { if (getDataSourceStream() != null) { return doFixedLengthFile(getDataSourceStream()); @@ -105,7 +105,7 @@ * puts together the dataset for fixed length file. This is used for PZ XML * mappings, and SQL table mappings */ - private IDataSet doFixedLengthFile(final InputStream dataSource) throws IOException { + private DataSet doFixedLengthFile(final InputStream dataSource) throws IOException { InputStreamReader isr = null; BufferedReader br = null; Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java 2006-11-27 13:22:39 UTC (rev 206) @@ -92,14 +92,14 @@ this.handlingShortLines = handleShortLines; } - public final IDataSet parse() { + public final DataSet parse() { if (!initialised) { init(); } return doParse(); } - protected abstract IDataSet doParse(); + protected abstract DataSet doParse(); protected abstract void init(); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java 2006-11-27 13:22:39 UTC (rev 206) @@ -124,7 +124,7 @@ } } - public IDataSet doParse() { + public DataSet doParse() { return null; } } Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java (from rev 205, trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java) =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-11-27 13:22:39 UTC (rev 206) @@ -0,0 +1,284 @@ +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. + * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package net.sf.pzfilereader; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import net.sf.pzfilereader.ordering.OrderBy; + +public interface DataSet { + + /** + * Goes to the top of the data set. This will put the pointer one record + * before the first in the set. Next() will have to be called to get the + * first record after this call. + */ + void goTop(); + + /** + * Goes to the last record in the dataset + */ + void goBottom(); + + /** + * Moves to the next record in the set. Returns true if move was a success, + * false if not + * + * @return boolean + */ + boolean next(); + + /** + * Moves back to the previous record in the set return true if move was a + * success, false if not + * + * @return boolean + */ + boolean previous(); + + /** + * Returns the string value of a specified column + * + * @param column - + * Name of the column + * @exception NoSuchElementException + * @return String + */ + String getString(final String column); + + /** + * Returns the double value of a specified column + * + * @param column - + * Name of the column + * @exception NoSuchElementException + * @exception NumberFormatException + * @return double + */ + double getDouble(final String column); + + /** + * Returns the interger value of a specified column + * + * @param column - + * Name of the column + * @exception NoSuchElementException + * @exception NumberFormatException + * @return double + */ + int getInt(final String column); + + /** + * Returns the date value of a specified column. This assumes the date is in + * yyyyMMdd. If your date is not in this format, see + * getDate(String,SimpleDateFormat) + * + * @param column - + * Name of the column + * @exception ParseException + * @return Date + */ + Date getDate(final String column) throws ParseException; + + /** + * Returns the date value of a specified column. This should be used if the + * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify + * what kind of format the date is in. + * + * @param column - + * Name of the column + * @param sdf - + * SimpleDateFormat of the date + * @exception ParseException + * @see java.text.SimpleDateFormat + * @return Date + */ + Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException; + + + /** + * Returns the value of the column with the type of object + * specified + * + * @param column + * Name of the column + * @param classToConvertTo + * Class type to convert to + * @return Object + * Value of the column in the specified object + */ + Object getObject(final String column, final Class classToConvertTo); + + /** + * Returns a String array of column names in the DataSet. This will assume + * 'detail' <RECORD> ID. + * + * @return String[] + */ + String[] getColumns(); + + /** + * Returns a String array of column names in the DataSet for a given + * <RECORD> id + * + * @param recordID + * @return String[] + */ + String[] getColumns(final String recordID); + + /** + * Returns the line number the pointer is on. These are the actual line + * numbers from the flat file, before any sorting. + * + * @exception NoSuchElementException + * @exception NumberFormatException + * @return int + */ + int getRowNo(); + + /** + * Returns A Collection Of DataErrors that happened during processing + * + * @return Vector + */ + List getErrors(); + + /** + * Removes a row from the dataset. Once the row is removed the pointer will + * be sitting on the record previous to the deleted row. + */ + void remove(); + + /** + * Returns the index the pointer is on for the array + * + * @return int + */ + int getIndex(); + + /** + * Returns the total number of rows parsed in from the file + * + * + * @return int - Row Count + */ + int getRowCount(); + + /** + * Returns total number of records which contained a parse error in the + * file. + * + * @return int - Record Error Count + */ + int getErrorCount(); + + /** + * Returns true or false as to whether or not the line number contains an + * error. The import will skip the line if it contains an error and it will + * not be processed + * + * @param lineNo - + * int line number + * @return boolean + */ + boolean isAnError(final int lineNo); + + /** + * Orders the data by column(s) specified. This will reposition the cursor + * to the top of the DataSet when executed. This is currently not supported + * when specying <RECORD> elements in the mapping. An exception will be + * thrown if this situation occurs + * + * @param ob - + * OrderBy object + * @exception Exception + * @see net.sf.pzfilereader.ordering.OrderBy + * @see net.sf.pzfilereader.ordering.OrderColumn + */ + void orderRows(final OrderBy ob) throws Exception; + + List getRows(); + + /** + * Sets data in the DataSet to lowercase + */ + void setLowerCase(); + + /** + * Sets data in the DataSet to uppercase + */ + void setUpperCase(); + + /** + * Checks to see if the row has the given <RECORD> id + * + * @param recordID + * @return boolean + */ + boolean isRecordID(final String recordID); + + /** + * Sets the absolute position of the record pointer + * + * @param localPointer - + * int + * @exception IndexOutOfBoundsException + */ + void absolute(final int localPointer); + + /** + * Setting this to True will parse text as is and throw a + * NumberFormatException. Setting to false, which is the default, will + * remove any non numeric charcter from the field. The remaining numeric + * chars's will be returned. If it is an empty string,or there are no + * numeric chars, 0 will be returned for getInt() and getDouble() + * + * @param strictNumericParse + * The strictNumericParse to set. + */ + void setStrictNumericParse(final boolean strictNumericParse); + + /** + * Sets the properties from the pzconvert.properties file. + * This file specifies the PZConverter implementation to use + * for a particular class + * + * @param props + * Property mapping for String to Object conversion + */ + void setPZConvertProps(Properties props); +} \ No newline at end of file Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-11-27 13:22:39 UTC (rev 206) @@ -54,7 +54,7 @@ * @author xhensevb * */ -public class DefaultDataSet implements IDataSet { +public class DefaultDataSet implements DataSet { private final List rows = new ArrayList(); private final List errors = new ArrayList(); Deleted: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-11-27 13:22:39 UTC (rev 206) @@ -1,284 +0,0 @@ -/* - * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. - * - * Based in London, we are world leaders in the design and development - * of bespoke applications for the securities financing markets. - * - * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> - * ___ _ _ _ _ _ - * / _ \| |__ (_) ___ ___| |_| | __ _| |__ - * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ - * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | - * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ - * |__/ - * - * www.ObjectLab.co.uk - * - * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ - * - * Copyright 2006 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package net.sf.pzfilereader; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Properties; - -import net.sf.pzfilereader.ordering.OrderBy; - -public interface IDataSet { - - /** - * Goes to the top of the data set. This will put the pointer one record - * before the first in the set. Next() will have to be called to get the - * first record after this call. - */ - void goTop(); - - /** - * Goes to the last record in the dataset - */ - void goBottom(); - - /** - * Moves to the next record in the set. Returns true if move was a success, - * false if not - * - * @return boolean - */ - boolean next(); - - /** - * Moves back to the previous record in the set return true if move was a - * success, false if not - * - * @return boolean - */ - boolean previous(); - - /** - * Returns the string value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @return String - */ - String getString(final String column); - - /** - * Returns the double value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @exception NumberFormatException - * @return double - */ - double getDouble(final String column); - - /** - * Returns the interger value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @exception NumberFormatException - * @return double - */ - int getInt(final String column); - - /** - * Returns the date value of a specified column. This assumes the date is in - * yyyyMMdd. If your date is not in this format, see - * getDate(String,SimpleDateFormat) - * - * @param column - - * Name of the column - * @exception ParseException - * @return Date - */ - Date getDate(final String column) throws ParseException; - - /** - * Returns the date value of a specified column. This should be used if the - * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify - * what kind of format the date is in. - * - * @param column - - * Name of the column - * @param sdf - - * SimpleDateFormat of the date - * @exception ParseException - * @see java.text.SimpleDateFormat - * @return Date - */ - Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException; - - - /** - * Returns the value of the column with the type of object - * specified - * - * @param column - * Name of the column - * @param classToConvertTo - * Class type to convert to - * @return Object - * Value of the column in the specified object - */ - Object getObject(final String column, final Class classToConvertTo); - - /** - * Returns a String array of column names in the DataSet. This will assume - * 'detail' <RECORD> ID. - * - * @return String[] - */ - String[] getColumns(); - - /** - * Returns a String array of column names in the DataSet for a given - * <RECORD> id - * - * @param recordID - * @return String[] - */ - String[] getColumns(final String recordID); - - /** - * Returns the line number the pointer is on. These are the actual line - * numbers from the flat file, before any sorting. - * - * @exception NoSuchElementException - * @exception NumberFormatException - * @return int - */ - int getRowNo(); - - /** - * Returns A Collection Of DataErrors that happened during processing - * - * @return Vector - */ - List getErrors(); - - /** - * Removes a row from the dataset. Once the row is removed the pointer will - * be sitting on the record previous to the deleted row. - */ - void remove(); - - /** - * Returns the index the pointer is on for the array - * - * @return int - */ - int getIndex(); - - /** - * Returns the total number of rows parsed in from the file - * - * - * @return int - Row Count - */ - int getRowCount(); - - /** - * Returns total number of records which contained a parse error in the - * file. - * - * @return int - Record Error Count - */ - int getErrorCount(); - - /** - * Returns true or false as to whether or not the line number contains an - * error. The import will skip the line if it contains an error and it will - * not be processed - * - * @param lineNo - - * int line number - * @return boolean - */ - boolean isAnError(final int lineNo); - - /** - * Orders the data by column(s) specified. This will reposition the cursor - * to the top of the DataSet when executed. This is currently not supported - * when specying <RECORD> elements in the mapping. An exception will be - * thrown if this situation occurs - * - * @param ob - - * OrderBy object - * @exception Exception - * @see net.sf.pzfilereader.ordering.OrderBy - * @see net.sf.pzfilereader.ordering.OrderColumn - */ - void orderRows(final OrderBy ob) throws Exception; - - List getRows(); - - /** - * Sets data in the DataSet to lowercase - */ - void setLowerCase(); - - /** - * Sets data in the DataSet to uppercase - */ - void setUpperCase(); - - /** - * Checks to see if the row has the given <RECORD> id - * - * @param recordID - * @return boolean - */ - boolean isRecordID(final String recordID); - - /** - * Sets the absolute position of the record pointer - * - * @param localPointer - - * int - * @exception IndexOutOfBoundsException - */ - void absolute(final int localPointer); - - /** - * Setting this to True will parse text as is and throw a - * NumberFormatException. Setting to false, which is the default, will - * remove any non numeric charcter from the field. The remaining numeric - * chars's will be returned. If it is an empty string,or there are no - * numeric chars, 0 will be returned for getInt() and getDouble() - * - * @param strictNumericParse - * The strictNumericParse to set. - */ - void setStrictNumericParse(final boolean strictNumericParse); - - /** - * Sets the properties from the pzconvert.properties file. - * This file specifies the PZConverter implementation to use - * for a particular class - * - * @param props - * Property mapping for String to Object conversion - */ - void setPZConvertProps(Properties props); -} \ No newline at end of file Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-11-27 13:22:39 UTC (rev 206) @@ -46,7 +46,7 @@ * * @return the data set resulting from parsing */ - IDataSet parse(); + DataSet parse(); /** * @return true, lines with less columns then the amount of column headers Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java 2006-11-27 13:22:39 UTC (rev 206) @@ -22,7 +22,7 @@ import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; /** * @author Paul Zepernick @@ -31,7 +31,7 @@ */ public class ExcelTransformer { - private IDataSet ds; + private DataSet ds; private File xlsFile; @@ -43,7 +43,7 @@ * @param xlsFile * Excel file to be created */ - public ExcelTransformer(final IDataSet ds, final File xlsFile) { + public ExcelTransformer(final DataSet ds, final File xlsFile) { this.ds = ds; this.xlsFile = xlsFile; } Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java 2006-11-27 13:22:39 UTC (rev 206) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -29,7 +29,7 @@ // text qualified by double quotes // ignore first record final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File("net/sf/pzfilereader/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"'); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name orderby = new OrderBy(); @@ -59,7 +59,7 @@ // used for Junit test - public IDataSet getDsForTest() throws Exception { + public DataSet getDsForTest() throws Exception { final PZParser parser = DefaultPZParserFactory.getInstance().newDelimitedParser( new File("src/test/java/net/sf/pzfilereader/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"'); Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFileTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFileTest.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFileTest.java 2006-11-27 13:22:39 UTC (rev 206) @@ -7,7 +7,7 @@ package net.sf.pzfilereader.columninfile; import junit.framework.TestCase; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; /** * @author zepernick @@ -22,7 +22,7 @@ // tests to make sure we have 0 errors public void testErrorCount() { - IDataSet ds = null; + DataSet ds = null; try { final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); @@ -41,7 +41,7 @@ // test to make sure we parsed the correct number // of rows in the file public void testRowCount() { - IDataSet ds = null; + DataSet ds = null; try { final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); @@ -59,7 +59,7 @@ // test to make sure we have the right number of column names from the file public void testColumnNameCount() { - IDataSet ds = null; + DataSet ds = null; try { final DelimitedColumnNamesInFile testDelimted = new DelimitedColumnNamesInFile(); Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java 2006-11-27 13:22:39 UTC (rev 206) @@ -9,7 +9,7 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DefaultPZParserFactory; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.PZParser; /** @@ -28,7 +28,7 @@ // ignore first record tmpFile = new File("net/sf/pzfilereader/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"); final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(tmpFile, '\t', '\"'); - final IDataSet ds = pzparser.parse(); + final DataSet ds = pzparser.parse(); // re order the data set by last name /* @@ -59,7 +59,7 @@ // used for Junit test - public IDataSet getDsForTest() throws Exception { + public DataSet getDsForTest() throws Exception { final PZParser parser = DefaultPZParserFactory.getInstance().newDelimitedParser( new File("src/test/java/net/sf/pzfilereader/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"), '\t', '\"'); Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimitedTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimitedTest.java 2006-11-26 14:01:12 UTC (rev 205) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimitedTest.java 2006-11-27 13:22:39 UTC (rev 206) @@ -7,7 +7,7 @@ package net.sf.pzfilereader.delim.tab; import junit.framework.TestCase; -import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.DataSet; /** * @author zepernick @@ -22,7 +22,7 @@ // tests to make sure we have 0 errors public void testErrorCount() { - IDataSet ds = null; + DataSet ds = null; try { final TabDelimited testTab = new TabDelimited(); @@ -41,7 +41,7 @@ // test to make sure we parsed the correct number // of rows in the file public void testRowCount() { - IDataSet ds = null; + DataSet ds = null; try { final TabDelimited testTab = new TabDelimited(); @@ -59,7 +59,7 @@ // test to make sure we have the right number of column names from the file public void testColumnNameCount() { - IDataSet ds = null; + DataSet ds = null; try { final TabDelimited testTab = new TabDelimited(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-26 14:01:14
|
Revision: 205 http://svn.sourceforge.net/pzfilereader/?rev=205&view=rev Author: zepernick Date: 2006-11-26 06:01:12 -0800 (Sun, 26 Nov 2006) Log Message: ----------- added test method in that was accidentally removed while combining with bx tests Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-26 13:55:21 UTC (rev 204) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-26 14:01:12 UTC (rev 205) @@ -140,6 +140,37 @@ check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "", "two", "", "three"}); } + /** + * Test some extreme cases + */ + public void testSomeExtremeCases2() { + check("\"a,b,c\"", ',', '\'', new String[] { "\"a", "b", "c\"" }); + check("\"a,b\",\"c\"", ',', '\'', new String[] { "\"a", "b\"", "\"c\"" }); + check("a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + + // example typically from Excel. + check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\'', new String[] { "\"test1\"", "test2", + "\"0.00\"", "\"another", "element here\"", "lastone" }); + + // what would you expect of these ones? + + // +++++The parser allows qualified and unqualified elements to be + // contained + // on the same line. so it should break the elements down like so + // 1 = a" -->" is part of the data since the element did not start with + // a qualifier + // 2 = b + // 3 = c" --> same as #1 + // a",b,c" + check("a\",b,c\"", ',', '\'', new String[] { "a\"", "b", "c\"" }); + + check("\" a,b,c\"", ',', '\'', new String[] { "\" a", "b", "c\"" }); + check(" a, b ,c ", ',', '\'', new String[] { "a", "b", "c" }); + + } + private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier, 10); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-26 13:55:21
|
Revision: 204 http://svn.sourceforge.net/pzfilereader/?rev=204&view=rev Author: zepernick Date: 2006-11-26 05:55:21 -0800 (Sun, 26 Nov 2006) Log Message: ----------- added a couple new checks Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-26 13:54:16 UTC (rev 203) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-26 13:55:21 UTC (rev 204) @@ -132,6 +132,8 @@ check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); + check("\"a, b,\"\"c\", \" test\"", ',', '\"', new String[] { "a, b,\"c", " test" }); + check("\"a, b,\"\"c\", test", ',', '\"', new String[] { "a, b,\"c", "test" }); check("one two three", ' ', '\u0000', new String[] {"one", "two", "three"}); check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "two", "three"}); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-26 13:54:17
|
Revision: 203 http://svn.sourceforge.net/pzfilereader/?rev=203&view=rev Author: zepernick Date: 2006-11-26 05:54:16 -0800 (Sun, 26 Nov 2006) Log Message: ----------- corrected a couple bugs where the double qualifier replace was not getting run. Tried to make the look ahead check a little more efficient preventing the substring and left trim where possible. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 20:29:14 UTC (rev 202) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-26 13:54:16 UTC (rev 203) @@ -143,6 +143,8 @@ String trimmed = trimmedLine.substring(startBlock, endBlock > startBlock ? endBlock : startBlock + 1); if (!blockWasInQualifier) { trimmed = trimmed.trim(); + } else { + //need to run the qualifier replace when it was in qualifier trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); } @@ -163,11 +165,13 @@ endBlock = i + 1; } } - //TODO - //this is probably a pretty costly check, maybe Benoit will have a better idea of how - //to handle + //try to first look ahead 1 char. If we have a match on the delimiter it will drop to the else + //otherwise do one last check to make sure there is no space between the delimiter and + //the qualifer. This looks a little sloppy, but I am trying to avoid the left trim, and substring if + //possible. else if (i + 1 < size && delimiter != ' ' && - lTrimKeepTabs(trimmedLine.substring(i + 1)).charAt(0) != delimiter) { + ((trimmedLine.charAt(i + 1) != ' ' && trimmedLine.charAt(i + 1) != delimiter) || + lTrimKeepTabs(trimmedLine.substring(i + 1)).charAt(0) != delimiter)) { previousChar = currentChar; endBlock = i + 1; continue; @@ -177,7 +181,9 @@ endBlock = i; // last column (e.g. finishes with ") if (i == size - 1) { - list.add(trimmedLine.substring(startBlock, size - 1)); + String str = trimmedLine.substring(startBlock, size - 1); + str = str.replaceAll(doubleQualifier, String.valueOf(qualifier)); + list.add(str); startBlock = i + 1; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 20:29:13
|
Revision: 202 http://svn.sourceforge.net/pzfilereader/?rev=202&view=rev Author: zepernick Date: 2006-11-25 12:29:14 -0800 (Sat, 25 Nov 2006) Log Message: ----------- fixed problem with qualifiers being allowed within the qualified element. Created a new issue. The check on line 134 of ParserUtilsSplitLineTest is failing. It seems to me like the check itself may be flawed on the end result. The parser looks like it is chopping off a " on the end of the element that should be there. Benoit, I left a note on what I updated. There is probably a better way that is going to make for a faster parse. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 19:59:07 UTC (rev 201) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 20:29:14 UTC (rev 202) @@ -130,6 +130,7 @@ for (int i = 0; i < size; i++) { final char currentChar = trimmedLine.charAt(i); + //System.out.println(currentChar); if (currentChar != delimiter && currentChar != qualifier) { previousChar = currentChar; endBlock = i + 1; @@ -161,6 +162,15 @@ } else { endBlock = i + 1; } + } + //TODO + //this is probably a pretty costly check, maybe Benoit will have a better idea of how + //to handle + else if (i + 1 < size && delimiter != ' ' && + lTrimKeepTabs(trimmedLine.substring(i + 1)).charAt(0) != delimiter) { + previousChar = currentChar; + endBlock = i + 1; + continue; } else { insideQualifier = false; blockWasInQualifier = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 19:59:07
|
Revision: 201 http://svn.sourceforge.net/pzfilereader/?rev=201&view=rev Author: zepernick Date: 2006-11-25 11:59:07 -0800 (Sat, 25 Nov 2006) Log Message: ----------- corrected javadoc Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 17:23:29 UTC (rev 200) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 19:59:07 UTC (rev 201) @@ -285,7 +285,7 @@ /** * Removes a single string character from a given string * - * @param character - + * @param theChar - * string char * @param theString - * string to search This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:23:30
|
Revision: 200 http://svn.sourceforge.net/pzfilereader/?rev=200&view=rev Author: zepernick Date: 2006-11-25 09:23:29 -0800 (Sat, 25 Nov 2006) Log Message: ----------- Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java 2006-11-25 17:23:17 UTC (rev 199) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java 2006-11-25 17:23:29 UTC (rev 200) @@ -19,5 +19,5 @@ * Static class which stores the version of this pzFileReader */ public class Version { - public static final String VERSION = "2.3.0"; + public static final String VERSION = "3.0.0"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:23:20
|
Revision: 199 http://svn.sourceforge.net/pzfilereader/?rev=199&view=rev Author: zepernick Date: 2006-11-25 09:23:17 -0800 (Sat, 25 Nov 2006) Log Message: ----------- copied over from bx test cases Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-25 17:22:30 UTC (rev 198) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-11-25 17:23:17 UTC (rev 199) @@ -42,7 +42,7 @@ final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_NO_BREAKS, d, q); - final List splitLineResults = ParserUtils.splitLine(txtToParse, d, q); + final List splitLineResults = ParserUtils.splitLine(txtToParse, d, q, 10); // check to make sure we have the same amount of elements which were // expected @@ -70,7 +70,7 @@ final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_WITH_BREAKS, d, q); - final List splitLineResults = ParserUtils.splitLine(txtToParse, d, q); + final List splitLineResults = ParserUtils.splitLine(txtToParse, d, q, 10); // check to make sure we have the same amount of elements which were // expected @@ -90,7 +90,7 @@ * data */ public void testMalformedData() { - final List splitLineResults = ParserUtils.splitLine(DELIMITED_BAD_DATA, ',', '\"'); + final List splitLineResults = ParserUtils.splitLine(DELIMITED_BAD_DATA, ',', '\"', 10); assertEquals("Expecting 2 Data Elements From The Malformed Data", 2, splitLineResults.size()); } @@ -101,12 +101,12 @@ public void testSomeExtremeCases() { check(null, ',', '\"', new String[] {}); check("a", ',', '\"', new String[] { "a" }); - check("", ',', '\"', new String[] { null }); - check(" ", ',', '\"', new String[] { null }); - check(" ", ',', '\"', new String[] { null }); - check(",", ',', '\"', new String[] { null, null }); - check(",,", ',', '\"', new String[] { null, null, null }); - check(",a,", ',', '\"', new String[] { null, "a", null }); + check("", ',', '\"', new String[] { "" }); + check(" ", ',', '\"', new String[] { "" }); + check(" ", ',', '\"', new String[] { "" }); + check(",", ',', '\"', new String[] { "", "" }); + check(",,", ',', '\"', new String[] { "", "", "" }); + check(",a,", ',', '\"', new String[] { "", "a", "" }); check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); @@ -119,53 +119,27 @@ // example typically from Excel. check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\"', new String[] { "test1", "test2", "0.00", "another, element here", "lastone" }); + + check("\"FRED\",\"ZNAME\",\"Text Qualifier \" and seperator, in string\",\"ELYRIA\",\"OH\",\"\"", ',', '\"', + new String[] {"FRED", "ZNAME", "Text Qualifier \" and seperator, in string", "ELYRIA", "OH", ""}); check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); check(" a, b ,c ", ',', '\"', new String[] { "a", "b", "c" }); check("\"a\", b , \"c\"", ',', '\"', new String[] { "a", "b", "c" }); - check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", null, null, null, "last one" }); - check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", null }); + check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", "", "", "", "last one" }); + check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", "" }); check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); - //++++looks like both quotes should be returned in the result here. - //let me know if I am wrong. pz - check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"\"c" }); + check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); + + check("one two three", ' ', '\u0000', new String[] {"one", "two", "three"}); + check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "two", "three"}); + check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "", "two", "", "three"}); } - /** - * Test some extreme cases - */ - public void testSomeExtremeCases2() { - check("\"a,b,c\"", ',', '\'', new String[] { "\"a", "b", "c\"" }); - check("\"a,b\",\"c\"", ',', '\'', new String[] { "\"a", "b\"", "\"c\"" }); - check("a,b,c", ',', '\'', new String[] { "a", "b", "c" }); - check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); - check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); - - // example typically from Excel. - check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\'', new String[] { "\"test1\"", "test2", - "\"0.00\"", "\"another", "element here\"", "lastone" }); - - // what would you expect of these ones? - - // +++++The parser allows qualified and unqualified elements to be - // contained - // on the same line. so it should break the elements down like so - // 1 = a" -->" is part of the data since the element did not start with - // a qualifier - // 2 = b - // 3 = c" --> same as #1 - // a",b,c" - check("a\",b,c\"", ',', '\'', new String[] { "a\"", "b", "c\"" }); - - check("\" a,b,c\"", ',', '\'', new String[] { "\" a", "b", "c\"" }); - check(" a, b ,c ", ',', '\'', new String[] { "a", "b", "c" }); - - } - private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { - final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier); + final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier, 10); assertEquals( "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", @@ -175,7 +149,6 @@ assertEquals("expecting...", expected[i], splitLineResults.get(i)); } } - public static void main(final String[] args) { junit.textui.TestRunner.run(ParserUtilsSplitLineTest.class); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:22:32
|
Revision: 198 http://svn.sourceforge.net/pzfilereader/?rev=198&view=rev Author: zepernick Date: 2006-11-25 09:22:30 -0800 (Sat, 25 Nov 2006) Log Message: ----------- converted to idataset Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java 2006-11-25 17:21:43 UTC (rev 197) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java 2006-11-25 17:22:30 UTC (rev 198) @@ -8,7 +8,6 @@ import java.io.File; import net.sf.pzfilereader.DataError; -import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; import net.sf.pzfilereader.IDataSet; import net.sf.pzfilereader.PZParser; @@ -23,14 +22,14 @@ */ public class DelimitedColumnNamesInFile { public static void main(final String[] args) throws Exception { - DataSet ds = null; String[] colNames = null; OrderBy orderby = null; // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File("net/sf/pzfilereader/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ",", "\"", false); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File("net/sf/pzfilereader/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"'); + final IDataSet ds = pzparser.parse(); // re order the data set by last name orderby = new OrderBy(); @@ -56,9 +55,6 @@ } } - // clear out the DataSet object for the JVM to collect - ds.freeMemory(); - } // used for Junit test Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java 2006-11-25 17:21:43 UTC (rev 197) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java 2006-11-25 17:22:30 UTC (rev 198) @@ -8,7 +8,6 @@ import java.io.File; import net.sf.pzfilereader.DataError; -import net.sf.pzfilereader.DataSet; import net.sf.pzfilereader.DefaultPZParserFactory; import net.sf.pzfilereader.IDataSet; import net.sf.pzfilereader.PZParser; @@ -21,7 +20,6 @@ */ public class TabDelimited { public static void main(final String[] args) throws Exception { - DataSet ds = null; String[] colNames = null; File tmpFile = null; @@ -29,9 +27,8 @@ // text qualified by double quotes // ignore first record tmpFile = new File("net/sf/pzfilereader/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt"); - System.out.println("tmp file path: " + tmpFile); - // ds = new DataSet(new FileInputStream(tmpFile),"\t","",true); - ds = new DataSet(tmpFile, "\t", "\"", true); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(tmpFile, '\t', '\"'); + final IDataSet ds = pzparser.parse(); // re order the data set by last name /* @@ -58,9 +55,6 @@ } } - // clear out the DataSet object for the JVM to collect - ds.freeMemory(); - } // used for Junit test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:21:44
|
Revision: 197 http://svn.sourceforge.net/pzfilereader/?rev=197&view=rev Author: zepernick Date: 2006-11-25 09:21:43 -0800 (Sat, 25 Nov 2006) Log Message: ----------- added bx parser Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/PZConstants.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-25 17:18:43 UTC (rev 196) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-25 17:21:43 UTC (rev 197) @@ -272,8 +272,13 @@ // end record line break logic // ******************************************************************** + //TODO + //seems like we may want to try doing something like this. I have my reservations because + //it is possible that we don't get a "detail" id and this might generate NPE + //is it going to create too much overhead to do a null check here as well??? + //final int intialSize = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, getColumnMD()).size(); // column values - final List columns = ParserUtils.splitLine(lineData, delimiter, qualifier); + final List columns = ParserUtils.splitLine(lineData, delimiter, qualifier, PZConstants.SPLITLINE_SIZE_INIT); lineData = ""; final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); final List cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/PZConstants.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/PZConstants.java 2006-11-25 17:18:43 UTC (rev 196) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/PZConstants.java 2006-11-25 17:21:43 UTC (rev 197) @@ -44,6 +44,8 @@ public static final String DELIMITED_FILE = "delimited"; public static final String FIXEDLENGTH_FILE = "fixed"; + + public static final int SPLITLINE_SIZE_INIT = 10; private PZConstants() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:18:52
|
Revision: 196 http://svn.sourceforge.net/pzfilereader/?rev=196&view=rev Author: zepernick Date: 2006-11-25 09:18:43 -0800 (Sat, 25 Nov 2006) Log Message: ----------- added bx parser Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 17:18:09 UTC (rev 195) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-11-25 17:18:43 UTC (rev 196) @@ -1,16 +1,34 @@ /* - Copyright 2006 Paul Zepernick - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed - under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the License. + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. + * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader.util; @@ -39,10 +57,12 @@ import net.sf.pzfilereader.xml.XMLRecordElement; /** - * @author zepernick Static utilities that are used to perform parsing in the + * Static utilities that are used to perform parsing in the * DataSet class These can also be used for low level parsing, if not * wishing to use the DataSet class. - * @version 2.0 + * + * @author Paul Zepernick + * @author Benoit Xhenseval */ public final class ParserUtils { private ParserUtils() { @@ -53,10 +73,11 @@ * @param line * @param delimiter * @param qualifier - * @return + * @return List */ public static List splitLine(final String line, final String delimiter, final String qualifier) { - return splitLine(line, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier.charAt(0) : 0); + return splitLine(line, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier.charAt(0) : 0, + PZConstants.SPLITLINE_SIZE_INIT); } /** @@ -67,136 +88,109 @@ * Elements which are not qualified will have leading and trailing white * space removed. This includes unqualified elements, which may be * contained in an unqualified parse: "data", data ,"data" + * + * Special thanks to Benoit for contributing this much improved speedy parser :0) * + * @author Benoit Xhenseval * @param line - * String of data to be parsed * @param delimiter - * Delimiter seperating each element * @param qualifier - * qualifier which is surrounding the text - * @return ArrayList + * @param initialSize - + * intial capacity of the List size + * @return List */ - public static List splitLine(String line, final char delimiter, final char qualifier) { - final ArrayList list = new ArrayList(); - - if (line == null) { + public static List splitLine(String line, final char delimiter, final char qualifier, int initialSize) { + List list = new ArrayList(initialSize); + + if (delimiter == 0) { + list.add(line); return list; - } else if (line.trim().length() == 0){ - list.add(null); + } else if (line == null) { return list; } - - boolean beginQualifier = false; - // this will be used for delimted files that have some items qualified - // and some items dont - boolean beginNoQualifier = false; - StringBuffer sb = new StringBuffer(); - // trim hard leading spaces at the begining of the line - line = lTrim(line); - for (int i = 0; i < line.length(); i++) { - final String remainderOfLine = line.substring(i); // data of the - // line which has not yet been read - // check to see if there is a text qualifier - final char currentChar = line.charAt(i); - if (qualifier > 0) { - if (currentChar == qualifier && !beginQualifier && !beginNoQualifier) { - // begining of a set of data - beginQualifier = true; - } else if (!beginQualifier && !beginNoQualifier && currentChar != qualifier - && lTrim(remainderOfLine).charAt(0) != qualifier) { - // try to account for empty space before qualifier starts - // we have not yet begun a qualifier and the char we are on - // is NOT a qualifier. Start reading data - beginNoQualifier = true; - // make sure that this is not just an empty column with no - // qualifiers. ie "data",,"data" - if (currentChar == delimiter) { - //list.add(sb.toString()); - list.add(null); - sb.delete(0, sb.length()); - beginNoQualifier = false; - continue;// grab the next char + final String trimmedLine = line.trim(); + int size = trimmedLine.length(); + + if (size == 0) { + list.add(""); + return list; + } + + boolean insideQualifier = false; + char previousChar = 0; + int startBlock = 0; + int endBlock = 0; + boolean blockWasInQualifier = false; + + final String doubleQualifier = String.valueOf(qualifier) + String.valueOf(qualifier); + for (int i = 0; i < size; i++) { + + final char currentChar = trimmedLine.charAt(i); + if (currentChar != delimiter && currentChar != qualifier) { + previousChar = currentChar; + endBlock = i + 1; + continue; + } + + if (currentChar == delimiter) { + // we've found the delimiter (eg ,) + if (!insideQualifier) { + String trimmed = trimmedLine.substring(startBlock, endBlock > startBlock ? endBlock : startBlock + 1); + if (!blockWasInQualifier) { + trimmed = trimmed.trim(); + trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); } - sb.append(currentChar); - } else if (!beginNoQualifier && currentChar == qualifier && beginQualifier - && (i == line.length() - 1 || lTrim(remainderOfLine.substring(1)).length() == 0 - // this will be true on empty undelmited columns at the - // end of theline - || lTrimKeepTabs(remainderOfLine).charAt(1) == delimiter)) { - // end of a set of data that was qualified - list.add(sb.toString()); - sb.delete(0, sb.length()); - beginQualifier = false; - // add to "i" so we can get past the qualifier, otherwise it - // is read into a set of data which - // may not be qualified. Find out how many spaces to the - // delimiter - final int offset = getDelimiterOffset(line, i, delimiter) - 1; - // subtract 1 since i is going to get incremented again at - // the top of the loop - if (offset < 1) { - i++; + + if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { + list.add(""); } else { - i += offset; + list.add(trimmed); } - } else if (beginNoQualifier && currentChar == delimiter) { - // check to see if we are done with an element that was not - // being qualified - // remove the space from the front and back of unqualified - // elements - list.add(lTrim(sb.toString().trim())); - sb.delete(0, sb.length()); - beginNoQualifier = false; - } else if (beginNoQualifier || beginQualifier) { - // getting data in a NO qualifier element or qualified - // element - sb.append(currentChar); + blockWasInQualifier = false; + startBlock = i + 1; } - - } else { - // not using a qualifier. Using a delimiter only - if (currentChar == delimiter) { - //remove the space from the front and back of unqualified - //elements - list.add(lTrim(sb.toString().trim())); - sb.delete(0, sb.length()); + } else if (currentChar == qualifier) { + if (!insideQualifier && previousChar != qualifier) { + if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { + insideQualifier = true; + startBlock = i + 1; + } else { + endBlock = i + 1; + } } else { - sb.append(currentChar); + insideQualifier = false; + blockWasInQualifier = true; + endBlock = i; + // last column (e.g. finishes with ") + if (i == size - 1) { + list.add(trimmedLine.substring(startBlock, size - 1)); + startBlock = i + 1; + } } } + previousChar = currentChar; } - // + this needs to be revisited... - final String trimmed = sb.toString().trim(); - // remove the ending text qualifier if needed - // only if the last element was truly qualified - if (beginQualifier && qualifier > 0 && trimmed.length() > 0) { - if (trimmed.charAt(trimmed.length() - 1) == qualifier) { - // System.out.println(">>>>>>>Triming Off Qualifier"); - final String s = trimmed.substring(0, trimmed.length() - 1); - sb.delete(0, sb.length()); - sb.append(s); + if (startBlock < size) { + String str = trimmedLine.substring(startBlock, size); + str = str.replaceAll(doubleQualifier, String.valueOf(qualifier)); + if (blockWasInQualifier) { + if (str.charAt(str.length() - 1) == qualifier) { + list.add(str.substring(0, str.length() - 1)); + } else { + list.add(str); + } + } else { + list.add(str.trim()); } + } else if (trimmedLine.charAt(size - 1) == delimiter) { + list.add(""); } - final String trimmed2 = line.trim(); - final int lengthLeft = trimmed2.length(); - if (qualifier <= 0 || beginQualifier || beginNoQualifier || lengthLeft > 0 - && trimmed2.charAt(lengthLeft - 1) == delimiter) { - // also account for a delimiter with an empty column at the end that - // was not qualified - // check to see if we need to add the last column in..this will - // happen on empty columns - // add the last column - list.add(!beginQualifier ? lTrim(trimToNull(sb.toString())) : sb.toString()); - //list.add(null); - } - - sb = null; - - list.trimToSize(); - return list; } @@ -340,7 +334,7 @@ continue; } - lineData = splitLine(line, delimiter.charAt(0), qualifier.charAt(0)); + lineData = splitLine(line, delimiter.charAt(0), qualifier.charAt(0), PZConstants.SPLITLINE_SIZE_INIT); for (int i = 0; i < lineData.size(); i++) { final ColumnMetaData cmd = new ColumnMetaData(); cmd.setColName((String) lineData.get(i)); @@ -382,7 +376,7 @@ final List results = new ArrayList(); final Map columnMD = new LinkedHashMap(); - lineData = splitLine(line, delimiter, qualifier); + lineData = splitLine(line, delimiter, qualifier, PZConstants.SPLITLINE_SIZE_INIT); for (int i = 0; i < lineData.size(); i++) { final ColumnMetaData cmd = new ColumnMetaData(); cmd.setColName((String) lineData.get(i)); @@ -422,7 +416,7 @@ continue; } - lineData = splitLine(line, delimiter.charAt(0), qualifier.charAt(0)); + lineData = splitLine(line, delimiter.charAt(0), qualifier.charAt(0), PZConstants.SPLITLINE_SIZE_INIT); for (int i = 0; i < lineData.size(); i++) { final ColumnMetaData cmd = new ColumnMetaData(); cmd.setColName((String) lineData.get(i)); @@ -663,7 +657,7 @@ final XMLRecordElement recordXMLElement = (XMLRecordElement) columnMD.get(key); if (recordXMLElement.getElementNumber() > lineElements.size()) { - // make sure our substring is not going to fail + // make sure the element referenced in the mapping exists continue; } final String lineElement = (String) lineElements.get(recordXMLElement.getElementNumber() - 1); @@ -930,4 +924,110 @@ throw new PZConvertException(ex); } } + + + //LEAVE AS A REFERENCE FOR POSSIBLE LATER USE + /* public static List splitLineWithBuf(String line, final char delimiter, char qualifier, int initialSize) { + List list = new ArrayList(initialSize); + + if (delimiter == 0) { + list.add(line); + return list; + } else if (line == null) { + return list; + } + + final String trimmedLine = line.trim(); + int size = trimmedLine.length(); + + if (size == 0) { + list.add(""); + return list; + } + + boolean insideQualifier = false; + char previousChar = 0; + boolean blockWasInQualifier = false; + StringBuffer buf = new StringBuffer(32); + + // final String doubleQualifier = String.valueOf(qualifier) + + // String.valueOf(qualifier); + for (int i = 0; i < size; i++) { + final char currentChar = trimmedLine.charAt(i); + if (currentChar != delimiter && currentChar != qualifier) { + previousChar = currentChar; + if (' ' != currentChar || insideQualifier || buf.length() > 0) { + buf.append(currentChar); + } + continue; + } + + if (currentChar == delimiter) { + // we've found the delimiter (eg ,) + if (!insideQualifier) { + // String trimmed = trimmedLine.substring(startBlock, + // endBlock > startBlock ? endBlock : startBlock + 1); + String trimmed = buf.toString(); + if (!blockWasInQualifier) { + trimmed = trimmed.trim(); + // trimmed = trimmed.replaceAll(doubleQualifier, + // String.valueOf(qualifier)); + } + + if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { + list.add(""); + } else { + list.add(trimmed); + } + blockWasInQualifier = false; + buf.delete(0, buf.length()); + } else if (buf.length() != 1 || buf.charAt(0) != qualifier) { + buf.append(currentChar); + } else { + buf.delete(0, buf.length()); + insideQualifier = false; + list.add(""); + } + } else if (currentChar == qualifier) { + if (!insideQualifier && previousChar != qualifier) { + if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { + insideQualifier = true; + int l = buf.length(); + if (l > 0) { + buf.delete(0, l); // just entered a + // qualifier, remove + // whatever was + } + } else { + buf.append(currentChar); + } + } else { + insideQualifier = false; + blockWasInQualifier = true; + if (previousChar == qualifier) { + buf.append(qualifier); + insideQualifier = true; + previousChar = 0; + continue; + } + // last column (e.g. finishes with ") + if (i == size - 1) { + // list.add(trimmedLine.substring(startBlock, size - + // 1)); + list.add(buf.toString()); + buf.delete(0, buf.length()); + } + } + } + previousChar = currentChar; + } + + if (buf.length() > 0) { + list.add(buf.toString().trim()); + } else if (trimmedLine.charAt(size - 1) == delimiter) { + list.add(""); + } + + return list; + }*/ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:18:09
|
Revision: 195 http://svn.sourceforge.net/pzfilereader/?rev=195&view=rev Author: zepernick Date: 2006-11-25 09:18:09 -0800 (Sat, 25 Nov 2006) Log Message: ----------- removing old code which is replaced by the IDataSet interface Removed Paths: ------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java Deleted: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-11-25 17:17:35 UTC (rev 194) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-11-25 17:18:09 UTC (rev 195) @@ -1,1400 +0,0 @@ -/* - Copyright 2006 Paul Zepernick - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed - under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the License. - */ -package net.sf.pzfilereader; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; - -import net.sf.pzfilereader.ordering.OrderBy; -import net.sf.pzfilereader.structure.ColumnMetaData; -import net.sf.pzfilereader.structure.Row; -import net.sf.pzfilereader.util.ExcelTransformer; -import net.sf.pzfilereader.util.FixedWidthParserUtils; -import net.sf.pzfilereader.util.PZConstants; -import net.sf.pzfilereader.util.ParserUtils; -import net.sf.pzfilereader.xml.PZMapParser; - -/** - * This class parses a datafile and holds methods to scroll back and forth - * through the datafile along with methods to retreive values from columns. - * - * @author Paul Zepernick - * @version 2.0.1 - * @todo Ought to implement an interface for the access to data. - */ -public class DataSet implements IDataSet { - /** Array to hold the rows and their values in the text file */ - private List rows = null; - - /** Array of errors that have occured during processing */ - private List errors = null; - - /** Map of column metadata's */ - private Map columnMD = null; - - /** Pointer for the current row in the array we are on */ - private int pointer = -1; - - /** flag to indicate if data should be pulled as lower case */ - private boolean lowerCase = false; - - /** flag to inidicate if data should be pulled as upper case */ - private boolean upperCase = false; - - /** - * flag to indicate if a strict parse should be used when getting doubles - * and ints - */ - private boolean strictNumericParse = false; - - /** - * Flag to indicate that we can cope with lines shorter than the required - * lengh - */ - private boolean handleShortLines = false; - - /** - * empty constructor. THIS SHOULD ONLY BE USED FOR CUSTOM DataSet - * implementations. It provides NO parsing abilities - */ - public DataSet() { - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a FIXED LENGTH text file. - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSource - - * Fixed length file to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final Connection con, final File dataSource, final String dataDefinition, final boolean handleShortLines) - throws Exception { - this(con, ParserUtils.createInputStream(dataSource), dataDefinition, handleShortLines); - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a FIXED LENGTH text file. - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, - final boolean handleShortLines) throws Exception { - super(); - this.handleShortLines = handleShortLines; - - ResultSet rs = null; - PreparedStatement stmt = null; - - try { - columnMD = new LinkedHashMap(); - - final String sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " - + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition - + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; - - stmt = con.prepareStatement(sql); // always use PreparedStatement - // as the DB can do clever - // things. - rs = stmt.executeQuery(); - - int recPosition = 1; - final List cmds = new ArrayList(); - // put array of columns together. These will be used to put together - // the dataset when reading in the file - while (rs.next()) { - - final ColumnMetaData column = new ColumnMetaData(); - column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); - column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); - column.setStartPosition(recPosition); - column.setEndPosition(recPosition + (rs.getInt("DATASTRUCTURE_LENGTH") - 1)); - recPosition += rs.getInt("DATASTRUCTURE_LENGTH"); - - cmds.add(column); - } - - columnMD.put(PZConstants.DETAIL_ID, cmds); - columnMD.put(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds)); - - if (cmds.isEmpty()) { - throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); - } - - // read in the fixed length file and construct the DataSet object - doFixedLengthFile(dataSourceStream); - - } finally { - if (rs != null) { - rs.close(); - } - if (stmt != null) { - stmt.close(); - } - } - - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a DELIMITED text file. esacpe sequence reference: \n - * newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSource - - * text file datasource to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - * @deprecated use the char version - */ - public DataSet(final Connection con, final File dataSource, final String dataDefinition, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(con, ParserUtils.createInputStream(dataSource), dataDefinition, delimiter, qualifier, ignoreFirstRecord, - handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * database table file layout method. This is used for a DELIMITED text - * file. esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - * @deprecated qualifier and delimiters should only be char. - */ - public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(con, dataSourceStream, dataDefinition, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier - .charAt(0) : 0, ignoreFirstRecord, handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * database table file layout method. This is used for a DELIMITED text - * file. esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final char delimiter, - final char qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - super(); - - this.handleShortLines = handleShortLines; - - ResultSet rs = null; - PreparedStatement stmt = null; - try { - columnMD = new LinkedHashMap(); - - final String sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " - + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition - + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; - - stmt = con.prepareStatement(sql); - rs = stmt.executeQuery(); // always use PreparedStatement as the - // DB can do clever things. - - final List cmds = new ArrayList(); - boolean hasResults = false; - // put array of columns together. These will be used to put together - // the dataset when reading in the file - while (rs.next()) { - - final ColumnMetaData column = new ColumnMetaData(); - column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); - column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); - cmds.add(column); - - hasResults = true; - } - - columnMD.put(PZConstants.DETAIL_ID, cmds); - columnMD.put(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds)); - - if (!hasResults) { - throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); - } - - // read in the fixed length file and construct the DataSet object - doDelimitedFile(dataSourceStream, delimiter, qualifier, ignoreFirstRecord, false); - - } finally { - if (rs != null) { - rs.close(); - } - if (stmt != null) { - stmt.close(); - } - } - - } - - /** - * Constructs a new DataSet using the PZMAP XML file layout method. This is - * used for a DELIMITED text file. esacpe sequence reference: \n newline - * <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXML - - * Reference to the xml file holding the pzmap - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - * @deprecated use the char version - */ - public DataSet(final File pzmapXML, final File dataSource, final String delimiter, final String qualifier, - final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(ParserUtils.createInputStream(pzmapXML), ParserUtils.createInputStream(dataSource), delimiter, qualifier, - ignoreFirstRecord, handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * PZMAP XML file layout method. This is used for a DELIMITED text file. - * esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - * @deprecated use the char version - */ - public DataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(pzmapXMLStream, dataSourceStream, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier - .charAt(0) : 0, ignoreFirstRecord, handleShortLines); - } - - /** - * Constructs a new DataSet using the PZMAP XML file layout method. This is - * used for a DELIMITED text file. esacpe sequence reference: \n newline - * <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXML - - * Reference to the xml file holding the pzmap - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, - final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(ParserUtils.createInputStream(pzmapXML), ParserUtils.createInputStream(dataSource), delimiter, qualifier, - ignoreFirstRecord, handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * PZMAP XML file layout method. This is used for a DELIMITED text file. - * esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, - final char qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - - this.handleShortLines = handleShortLines; - columnMD = PZMapParser.parse(pzmapXMLStream); - - doDelimitedFile(dataSourceStream, delimiter, qualifier, ignoreFirstRecord, false); - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - * @deprecated - */ - public DataSet(final File dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) - throws Exception { - this(dataSource, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier.charAt(0) : 0, - handleShortLines); - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public DataSet(final File dataSource, final char delimiter, final char qualifier, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - InputStream dataSourceStream = null; - - try { - dataSourceStream = ParserUtils.createInputStream(dataSource); - doDelimitedFile(dataSourceStream, delimiter, qualifier, false, true); - } finally { - if (dataSourceStream != null) { - dataSourceStream.close(); - } - } - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - * @deprecated - */ - public DataSet(final InputStream dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) - throws Exception { - this(dataSource, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier.charAt(0) : 0, - handleShortLines); - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public DataSet(final InputStream dataSource, final char delimiter, final char qualifier, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - - try { - doDelimitedFile(dataSource, delimiter, qualifier, false, true); - } finally { - if (dataSource != null) { - dataSource.close(); - } - } - } - - /** - * Constructs a new DataSet using the PZMAP XML file layout method. This is - * used for a FIXED LENGTH text file. - * - * @param pzmapXML - - * Reference to the xml file holding the pzmap - * @param dataSource - - * Delimited file to read from - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final File pzmapXML, final File dataSource, final boolean handleShortLines) throws Exception { - this(ParserUtils.createInputStream(pzmapXML), ParserUtils.createInputStream(dataSource), handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * PZMAP XML file layout method. This is used for a FIXED LENGTH text file. - * - * @param pzmapXMLStream - - * Reference to the xml file InputStream holding the pzmap - * @param dataSourceStream - - * Delimited file InputStream to read from - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - - columnMD = PZMapParser.parse(pzmapXMLStream); - - // read in the fixed length file and construct the DataSet object - doFixedLengthFile(dataSourceStream); - } - - /* - * This is the new version of doDelimitedFile using InputStrem instead of - * File. This is more flexible especially it is working with WebStart. - * - * puts together the dataset for fixed length file. This is used for PZ XML - * mappings, and SQL table mappings - */ - private void doFixedLengthFile(final InputStream dataSource) throws Exception { - InputStreamReader isr = null; - BufferedReader br = null; - - try { - rows = new ArrayList(); - errors = new ArrayList(); - - final Map recordLengths = ParserUtils.calculateRecordLengths(columnMD); - - // Read in the flat file - isr = new InputStreamReader(dataSource); - br = new BufferedReader(isr); - String line = null; - int lineCount = 0; - // map of record lengths corrisponding to the ID's in the columnMD - // array - // loop through each line in the file - while ((line = br.readLine()) != null) { - lineCount++; - // empty line skip past it - if (line.trim().length() == 0) { - continue; - } - - final String mdkey = FixedWidthParserUtils.getCMDKey(columnMD, line); - final int recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); - - // Incorrect record length on line log the error. Line will not - // be included in the - // dataset - if (line.length() > recordLength) { - addError("LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2); - continue; - } else if (line.length() < recordLength) { - if (handleShortLines) { - // We can pad this line out - line += ParserUtils.padding(recordLength - line.length(), ' '); - - // log a warning - addError("PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1); - - } else { - addError("LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2); - continue; - } - } - - // int recPosition = 1; - final Row row = new Row(); - row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try - - final List cmds = ParserUtils.getColumnMetaData(mdkey, columnMD); - row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); - // to limit the memory use - // Build the columns for the row - // for (int i = 0; i < cmds.size(); i++) { - // final String tempValue = line.substring(recPosition - 1, - // recPosition - // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); - // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); - // row.addColumn(tempValue.trim()); - // } - row.setRowNumber(lineCount); - // add the row to the array - rows.add(row); - } - } finally { - if (isr != null) { - isr.close(); - } - if (br != null) { - br.close(); - } - } - } - - /* - * This is the new version of doDelimitedFile using InputStrem instead of - * File. This is more flexible especially it is working with WebStart. - * - * puts together the dataset for a DELIMITED file. This is used for PZ XML - * mappings, and SQL table mappings - */ - private void doDelimitedFile(final InputStream dataSource, final char delimiter, final char qualifier, - final boolean ignoreFirstRecord, final boolean createMDFromFile) throws Exception { - if (dataSource == null) { - throw new NullPointerException("dataSource is null"); - } - - InputStreamReader isr = null; - BufferedReader br = null; - - try { - rows = new ArrayList(); - errors = new ArrayList(); - - // get the total column count - // columnCount = columnMD.size(); - - /** Read in the flat file */ - // fr = new FileReader(dataSource.getAbsolutePath()); - isr = new InputStreamReader(dataSource); - br = new BufferedReader(isr); - - boolean processedFirst = false; - boolean processingMultiLine = false; - int lineCount = 0; - String lineData = ""; - /** loop through each line in the file */ - String line = null; - while ((line = br.readLine()) != null) { - lineCount++; - /** empty line skip past it */ - final String trimmed = line.trim(); - if (!processingMultiLine && trimmed.length() == 0) { - continue; - } - - // check to see if the user has elected to skip the first record - if (!processedFirst && ignoreFirstRecord) { - processedFirst = true; - continue; - } else if (!processedFirst && createMDFromFile) { - processedFirst = true; - columnMD = ParserUtils.getColumnMDFromFile(line, delimiter, qualifier); - continue; - } - - // ******************************************************** - // new functionality as of 2.1.0 check to see if we have - // any line breaks in the middle of the record, this will only - // be checked if we have specified a delimiter - // ******************************************************** - final char[] chrArry = trimmed.toCharArray(); - if (!processingMultiLine && delimiter > 0) { - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - } - - // check to see if we have reached the end of the linebreak in - // the record - - final String trimmedLineData = lineData.trim(); - if (processingMultiLine && trimmedLineData.length() > 0) { - // need to do one last check here. it is possible that the " - // could be part of the data - // excel will escape these with another quote; here is some - // data "" This would indicate - // there is more to the multiline - if (trimmed.charAt(trimmed.length() - 1) == qualifier && !trimmed.endsWith("" + qualifier + qualifier)) { - // it is safe to assume we have reached the end of the - // line break - processingMultiLine = false; - if (trimmedLineData.length() > 0) { // + would always be - // true surely.... - lineData += "\r\n"; - } - lineData += line; - } else { - // check to see if this is the last line of the record - // looking for a qualifier followed by a delimiter - if (trimmedLineData.length() > 0) { // + here again, - // this should - // always be true... - lineData += "\r\n"; - } - lineData += line; - boolean qualiFound = false; - for (int i = 0; i < chrArry.length; i++) { - if (qualiFound) { - if (chrArry[i] == ' ') { - continue; - } else { - // not a space, if this char is the - // delimiter, then we have reached the end - // of - // the record - if (chrArry[i] == delimiter) { - // processingMultiLine = false; - // fix put in, setting to false caused - // bug when processing multiple - // multi-line - // columns on the same record - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - break; - } - qualiFound = false; - continue; - } - } else if (chrArry[i] == qualifier) { - qualiFound = true; - } - } - // check to see if we are still in multi line mode, if - // so grab the next line - if (processingMultiLine) { - continue; - } - } - } else { - // throw the line into lineData var. - lineData += line; - if (processingMultiLine) { - continue; // if we are working on a multiline rec, get - // the data on the next line - } - } - // ******************************************************************** - // end record line break logic - // ******************************************************************** - - // column values - final List columns = ParserUtils.splitLine(lineData, delimiter, qualifier); - lineData = ""; - final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(columnMD, columns); - final List cmds = ParserUtils.getColumnMetaData(mdkey, columnMD); - final int columnCount = cmds.size(); - // DEBUG - - // Incorrect record length on line log the error. Line - // will not be included in the dataset - if (columns.size() > columnCount) { - // log the error - addError("TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } else if (columns.size() < columnCount) { - if (handleShortLines) { - // We can pad this line out - while (columns.size() < columnCount) { - columns.add(""); - } - - // log a warning - addError("PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1); - - } else { - addError("TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } - } - - final Row row = new Row(); - row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try - // to limit the memory use - row.setCols(columns); - row.setRowNumber(lineCount); - /** add the row to the array */ - rows.add(row); - } - } finally { - if (isr != null) { - isr.close(); - } - if (br != null) { - br.close(); - } - } - } - - /** - * Changes the value of a specified column in a row in the set. This change - * is in memory, and does not actually change the data in the file that was - * read in. - * - * @param columnName - - * String Name of the column - * @param value - - * String value to assign to the column. - * @exception Exception - - * exception will be thrown if pointer in not on a valid row - */ - public void setValue(final String columnName, final String value) throws Exception { - /** get a reference to the row */ - final Row row = (Row) rows.get(pointer); - - final int idx = ParserUtils.getColumnIndex(row.getMdkey(), columnMD, columnName); - row.setValue(idx, value); - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - /** change the value of the column */ - // row.setValue(ParserUtils.findColumn(columnName, cmds), value); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#goTop() - */ - public void goTop() { - pointer = -1; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#goBottom() - */ - public void goBottom() { - pointer = rows.size() - 1; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#next() - */ - public boolean next() { - if (pointer < rows.size() && pointer + 1 != rows.size()) { - pointer++; - return true; - } - return false; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#previous() - */ - public boolean previous() { - if (pointer <= 0) { - return false; - } - pointer--; - return true; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getString(java.lang.String) - */ - public String getString(final String column) { - final Row row = (Row) rows.get(pointer); - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); - - if (upperCase) { - // convert data to uppercase before returning - // return row.getValue(ParserUtils.findColumn(column, - // cmds)).toUpperCase(Locale.getDefault()); - return s.toUpperCase(Locale.getDefault()); - } - - if (lowerCase) { - // convert data to lowercase before returning - // return row.getValue(ParserUtils.findColumn(column, - // cmds)).toLowerCase(Locale.getDefault()); - return s.toLowerCase(Locale.getDefault()); - } - - // return value as how it is in the file - // return row.getValue(ParserUtils.findColumn(column, cmds)); - return s; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getDouble(java.lang.String) - */ - public double getDouble(final String column) { - final StringBuffer newString = new StringBuffer(); - final Row row = (Row) rows.get(pointer); - - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - // String s = ((Row) - // rows.get(pointer)).getValue(ParserUtils.findColumn(column, cmds)); - final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); - - if (!strictNumericParse) { - if (s.trim().length() == 0) { - return 0; - } - for (int i = 0; i < s.length(); i++) { - final char c = s.charAt(i); - if (c >= '0' && c <= '9' || c == '.' || c == '-') { - newString.append(c); - } - } - if (newString.length() == 0 || (newString.length() == 1 && newString.toString().equals(".")) - || (newString.length() == 1 && newString.toString().equals("-"))) { - newString.append("0"); - } - } else { - newString.append(s); - } - - return Double.parseDouble(newString.toString()); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getInt(java.lang.String) - */ - public int getInt(final String column) { - final StringBuffer newString = new StringBuffer(); - final Row row = (Row) rows.get(pointer); - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - // - // String s = row.getValue(ParserUtils.findColumn(column, cmds)); - final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); - - if (!strictNumericParse) { - if (s.trim().length() == 0) { - return 0; - } - for (int i = 0; i < s.length(); i++) { - final char c = s.charAt(i); - if (c >= '0' && c <= '9' || c == '-') { - newString.append(c); - } - } - // check to make sure we do not have a single length string with - // just a minus sign - if (newString.length() == 0 || (newString.length() == 1 && newString.toString().equals("-"))) { - newString.append("0"); - } - } else { - newString.append(s); - } - - return Integer.parseInt(newString.toString()); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String) - */ - public Date getDate(final String column) throws ParseException { - final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - final Row row = (Row) rows.get(pointer); - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - - // String s = row.getValue(ParserUtils.findColumn(column, cmds)); - final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); - return sdf.parse(s); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String, - * java.text.SimpleDateFormat) - */ - public Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException { - final Row row = (Row) rows.get(pointer); - // final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), - // columnMD); - // - // String s = row.getValue(ParserUtils.findColumn(column, cmds)); - final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); - return sdf.parse(s); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getColumns() - */ - public String[] getColumns() { - ColumnMetaData column = null; - String[] array = null; - - if (columnMD != null) { - final List cmds = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, columnMD); - - array = new String[cmds.size()]; - for (int i = 0; i < cmds.size(); i++) { - column = (ColumnMetaData) cmds.get(i); - array[i] = column.getColName(); - } - } - - return array; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getColumns(java.lang.String) - */ - public String[] getColumns(final String recordID) { - String[] array = null; - - if (columnMD != null) { - final List cmds = ParserUtils.getColumnMetaData(recordID, columnMD); - array = new String[cmds.size()]; - for (int i = 0; i < cmds.size(); i++) { - final ColumnMetaData column = (ColumnMetaData) cmds.get(i); - array[i] = column.getColName(); - } - } - - return array; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getRowNo() - */ - public int getRowNo() { - return ((Row) rows.get(pointer)).getRowNumber(); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getErrors() - */ - public List getErrors() { - return errors; - } - - /** - * Adds a new error to this DataSet. These can be collected, and retreived - * after processing - * - * @param errorDesc - - * String description of error - * @param lineNo - - * int line number error occured on - * @param errorLevel - - * int errorLevel 1,2,3 1=warning 2=error 3= severe error - */ - public void addError(final String errorDesc, final int lineNo, final int errorLevel) { - final DataError de = new DataError(); - de.setErrorDesc(errorDesc); - de.setLineNo(lineNo); - de.setErrorLevel(errorLevel); - errors.add(de); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#remove() - */ - public void remove() { - rows.remove(pointer); - pointer--; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getIndex() - */ - public int getIndex() { - return pointer; - } - - /** - * Sets the absolute position of the record pointer - * - * @param localPointer - - * int - * @exception IndexOutOfBoundsException - */ - public void absolute(final int localPointer) { - if (localPointer < 0 || localPointer > rows.size() - 1) { - throw new IndexOutOfBoundsException("INVALID POINTER LOCATION: " + localPointer); - } - - pointer = localPointer; - } - - /** - * Checks to see if the row has the given <RECORD> id - * - * @param recordID - * @return boolean - */ - public boolean isRecordID(final String recordID) { - String rowID = ((Row) rows.get(pointer)).getMdkey(); - if (rowID == null) { - rowID = PZConstants.DETAIL_ID; - } - - return rowID.equals(recordID); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getRowCount() - */ - public int getRowCount() { - return rows.size(); - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getErrorCount() - */ - public int getErrorCount() { - if (getErrors() != null) { - return getErrors().size(); - } - - return 0; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#isAnError(int) - */ - public boolean isAnError(final int lineNo) { - for (int i = 0; i < errors.size(); i++) { - if (((DataError) errors.get(i)).getLineNo() == lineNo && ((DataError) errors.get(i)).getErrorLevel() > 1) { - return true; - } - } - return false; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#orderRows(net.sf.pzfilereader.ordering.OrderBy) - */ - public void orderRows(final OrderBy ob) throws Exception { - // PZ try to handle other <records> by sending them to - // the bottom of the sort - // if (columnMD.size() > 1) { - // throw new Exception("orderRows does not currently support ordering - // with <RECORD> mappings"); - // } - if (ob != null && rows != null) { - final List cmds = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, columnMD); - ob.setColumnMD(cmds); - Collections.sort(rows, ob); - goTop(); - } - } - - /** - * Sets data in the DataSet to lowercase - */ - public void setLowerCase() { - upperCase = false; - lowerCase = true; - } - - /** - * Sets data in the DataSet to uppercase - */ - public void setUpperCase() { - upperCase = true; - lowerCase = false; - } - - /** - * Setting this to True will parse text as is and throw a - * NumberFormatException. Setting to false, which is the default, will - * remove any non numeric charcter from the field. The remaining numeric - * chars's will be returned. If it is an empty string,or there are no - * numeric chars, 0 will be returned for getInt() and getDouble() - * - * @param strictNumericParse - * The strictNumericParse to set. - */ - public void setStrictNumericParse(final boolean strictNumericParse) { - this.strictNumericParse = strictNumericParse; - } - - /** - * Erases the dataset early and releases memory for the JVM to reclaim, this - * invalidates the object. - * - * @deprecated You can still use it but truly you should keep the scope of - * the DataSet to a MINIMUM. - */ - public void freeMemory() { - if (rows != null) { - rows.clear(); - } - if (errors != null) { - errors.clear(); - } - if (columnMD != null) { - columnMD.clear(); - } - } - - /** - * Writes this current DataSet out to the specified Excel file - * - * @param excelFileToBeWritten - * @exception Exception - */ - public void writeToExcel(final File excelFileToBeWritten) throws Exception { - final ExcelTransformer et = new ExcelTransformer(this, excelFileToBeWritten); - et.writeExcelFile(); - } - - /** - * Returns the version number of this pzFileReader - * - * @return String - */ - public String getReaderVersion() { - return Version.VERSION; - } - - /** - * @return Returns the handleShortLines. - */ - public boolean isHandleShortLines() { - return handleShortLines; - } - - /** - * This is used for LargeDataSet compatability. Setting this will have no - * affect on the DataSet parser. It must be passed on the constructor - * - * @param handleShortLines - * The handleShortLines to set. - */ - public void setHandleShortLines(final boolean handleShortLines) { - this.handleShortLines = handleShortLines; - } - - public Map getColumnMD() { - return columnMD; - } - - public void setColumnMD(final Map columnMD) { - this.columnMD = columnMD; - } - - /* - * (non-Javadoc) - * - * @see net.sf.pzfilereader.IDataSet#getRows() - */ - public List getRows() { - return rows; - } - - public void setRows(final List rows) { - this.rows = rows; - } - - public void setErrors(final List errors) { - this.errors = errors; - } - - public Object getObject(String column, Class classToConvertTo) { - // TODO May have to do something here if we plan on keeping - //this around for the next version. I believe this will - //be leaving - return null; - } - - public void setPZConvertProps(Properties props) { - // TODO May have to do something here if we plan on keeping - //this around for the next version. I believe this will - //be leaving - } -} Deleted: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-11-25 17:17:35 UTC (rev 194) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-11-25 17:18:09 UTC (rev 195) @@ -1,647 +0,0 @@ -/* - Copyright 2006 Paul Zepernick - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed - under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the License. - */ -package net.sf.pzfilereader; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import net.sf.pzfilereader.ordering.OrderBy; -import net.sf.pzfilereader.structure.Row; -import net.sf.pzfilereader.util.FixedWidthParserUtils; -import net.sf.pzfilereader.util.PZConstants; -import net.sf.pzfilereader.util.ParserUtils; -import net.sf.pzfilereader.xml.PZMapParser; - -/** - * @author Paul Zepernick - * - * Provides limited DataSet functionality for large files. This will not read - * the file into memory. The following methods have been disabled previous(), - * goTop(), goBottom(), remove(), getIndex(), absolute(), orderRows() - */ -public class LargeDataSet extends DataSet { - private String fileType; // file type being parsed - - private BufferedReader br = null; // reader used to read the file - - private InputStreamReader isr = null; - - private InputStream is = null; // stream used to read the file - - private int lineCount = 0; // keeps track of the current line being - - // procssed in the file - - // used for delimited files - private boolean ignoreFirstRecord = false; - - private boolean createMDFromFile = false; - - private boolean processedFirst = false; - - private char delimiter = 0; - - private char qualifier = 0; - - private int columnCount = 0; - - /** - * used for fixed length files, map of record lengths corresponding to the - * ID's in the columnMD array. - */ - private Map recordLengths = null; - - /** - * Constructor based on InputStream. Constructs a new LargeDataSet using the - * PZMAP XML file layout method. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - * @deprecated use the char version. - */ - public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(pzmapXMLStream, dataSourceStream, delimiter != null ? delimiter.charAt(0) : 0, qualifier != null ? qualifier - .charAt(0) : 0, ignoreFirstRecord, handleShortLines); - } - - /** - * Constructor based on InputStream. Constructs a new LargeDataSet using the - * PZMAP XML file layout method. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, - final char qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - - this.fileType = PZConstants.DELIMITED_FILE; - this.is = dataSourceStream; - this.isr = new InputStreamReader(is); - this.br = new BufferedReader(this.isr); - this.delimiter = delimiter; - this.qualifier = qualifier; - this.ignoreFirstRecord = ignoreFirstRecord; - setHandleShortLines(handleShortLines); - setColumnMD(PZMapParser.parse(pzmapXMLStream)); - - } - - /** - * Constructs a new LargeDataSet using the first line of data found in the - * text file as the column names. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @... [truncated message content] |
From: <zep...@us...> - 2006-11-25 17:17:35
|
Revision: 194 http://svn.sourceforge.net/pzfilereader/?rev=194&view=rev Author: zepernick Date: 2006-11-25 09:17:35 -0800 (Sat, 25 Nov 2006) Log Message: ----------- moved parser's into ParserUtils Removed Paths: ------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java Deleted: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-11-25 17:17:25 UTC (rev 193) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-11-25 17:17:35 UTC (rev 194) @@ -1,213 +0,0 @@ -/** - * - */ -package net.sf.pzfilereader.util; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author xhensevb - * - */ -public class BXParser { - public static List splitLine(String line, final char delimiter, char qualifier) { - return splitLine(line, delimiter, qualifier, 10); - } - - public static List splitLine(String line, final char delimiter, char qualifier, int initialSize) { - List list = new ArrayList(initialSize); - - if (delimiter == 0) { - list.add(line); - return list; - } else if (line == null) { - return list; - } - - final String trimmedLine = line.trim(); - int size = trimmedLine.length(); - - if (size == 0) { - list.add(""); - return list; - } - - boolean insideQualifier = false; - char previousChar = 0; - int startBlock = 0; - int endBlock = 0; - boolean blockWasInQualifier = false; - - final String doubleQualifier = String.valueOf(qualifier) + String.valueOf(qualifier); - for (int i = 0; i < size; i++) { - - final char currentChar = trimmedLine.charAt(i); - if (currentChar != delimiter && currentChar != qualifier) { - previousChar = currentChar; - endBlock = i + 1; - continue; - } - - if (currentChar == delimiter) { - // we've found the delimiter (eg ,) - if (!insideQualifier) { - String trimmed = trimmedLine.substring(startBlock, endBlock > startBlock ? endBlock : startBlock + 1); - if (!blockWasInQualifier) { - trimmed = trimmed.trim(); - trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); - } - - if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { - list.add(""); - } else { - list.add(trimmed); - } - blockWasInQualifier = false; - startBlock = i + 1; - } - } else if (currentChar == qualifier) { - if (!insideQualifier && previousChar != qualifier) { - if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { - insideQualifier = true; - startBlock = i + 1; - } else { - endBlock = i + 1; - } - } else { - insideQualifier = false; - blockWasInQualifier = true; - endBlock = i; - // last column (e.g. finishes with ") - if (i == size - 1) { - list.add(trimmedLine.substring(startBlock, size - 1)); - startBlock = i + 1; - } - } - } - previousChar = currentChar; - } - - if (startBlock < size) { - String str = trimmedLine.substring(startBlock, size); - str = str.replaceAll(doubleQualifier, String.valueOf(qualifier)); - if (blockWasInQualifier) { - if (str.charAt(str.length() - 1) == qualifier) { - list.add(str.substring(0, str.length() - 1)); - } else { - list.add(str); - } - } else { - list.add(str.trim()); - } - } else if (trimmedLine.charAt(size - 1) == delimiter) { - list.add(""); - } - - return list; - } - - public static List splitLineWithBuf(String line, final char delimiter, char qualifier, int initialSize) { - List list = new ArrayList(initialSize); - - if (delimiter == 0) { - list.add(line); - return list; - } else if (line == null) { - return list; - } - - final String trimmedLine = line.trim(); - int size = trimmedLine.length(); - - if (size == 0) { - list.add(""); - return list; - } - - boolean insideQualifier = false; - char previousChar = 0; - boolean blockWasInQualifier = false; - StringBuffer buf = new StringBuffer(32); - - // final String doubleQualifier = String.valueOf(qualifier) + - // String.valueOf(qualifier); - for (int i = 0; i < size; i++) { - final char currentChar = trimmedLine.charAt(i); - if (currentChar != delimiter && currentChar != qualifier) { - previousChar = currentChar; - if (' ' != currentChar || insideQualifier || buf.length() > 0) { - buf.append(currentChar); - } - continue; - } - - if (currentChar == delimiter) { - // we've found the delimiter (eg ,) - if (!insideQualifier) { - // String trimmed = trimmedLine.substring(startBlock, - // endBlock > startBlock ? endBlock : startBlock + 1); - String trimmed = buf.toString(); - if (!blockWasInQualifier) { - trimmed = trimmed.trim(); - // trimmed = trimmed.replaceAll(doubleQualifier, - // String.valueOf(qualifier)); - } - - if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { - list.add(""); - } else { - list.add(trimmed); - } - blockWasInQualifier = false; - buf.delete(0, buf.length()); - } else if (buf.length() != 1 || buf.charAt(0) != qualifier) { - buf.append(currentChar); - } else { - buf.delete(0, buf.length()); - insideQualifier = false; - list.add(""); - } - } else if (currentChar == qualifier) { - if (!insideQualifier && previousChar != qualifier) { - if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { - insideQualifier = true; - int l = buf.length(); - if (l > 0) { - buf.delete(0, l); // just entered a - // qualifier, remove - // whatever was - } - } else { - buf.append(currentChar); - } - } else { - insideQualifier = false; - blockWasInQualifier = true; - if (previousChar == qualifier) { - buf.append(qualifier); - insideQualifier = true; - previousChar = 0; - continue; - } - // last column (e.g. finishes with ") - if (i == size - 1) { - // list.add(trimmedLine.substring(startBlock, size - - // 1)); - list.add(buf.toString()); - buf.delete(0, buf.length()); - } - } - } - previousChar = currentChar; - } - - if (buf.length() > 0) { - list.add(buf.toString().trim()); - } else if (trimmedLine.charAt(size - 1) == delimiter) { - list.add(""); - } - - return list; - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:17:25
|
Revision: 193 http://svn.sourceforge.net/pzfilereader/?rev=193&view=rev Author: zepernick Date: 2006-11-25 09:17:25 -0800 (Sat, 25 Nov 2006) Log Message: ----------- moved parser's into ParserUtils Removed Paths: ------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java Deleted: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-11-25 17:16:58 UTC (rev 192) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-11-25 17:17:25 UTC (rev 193) @@ -1,153 +0,0 @@ -package net.sf.pzfilereader.parserutils; - -import java.util.List; - -import junit.framework.TestCase; -import net.sf.pzfilereader.util.BXParser; -import net.sf.pzfilereader.utilities.UnitTestUtils; - -/** - * Test the functionality of the splitLine method. This method returns a List of - * Strings. Each element of the list represents a column created by the parser - * from the delimited String. - * - * @author Paul Zepernick - */ -public class BXParserTest extends TestCase { - private static final String[] DELIMITED_DATA_NO_BREAKS = { "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; - - private static final String[] DELIMITED_DATA_WITH_BREAKS = { "Column 1 \r\n\r\n Test After Break \r\n Another Break", - "Column 2", "Column 3 \r\n\r\n Test After Break", "Column 4", "Column 5 \r\n\r\n Test After Break\r\n Another Break" }; - - // TODO think of a situation that actually breaks the parse. This still - // works because of the way it is coded - // to handle the excel CSV. Excel CSV has some elements qualified and others - // not - private static final String DELIMITED_BAD_DATA = "\"column 1\",\"column 2 ,\"column3\""; - - // 0 = delimiter - // 1 = qualifier - private static final char[][] DELIM_QUAL_PAIR = { { ',', '\"' }, { '\t', '\"' }, { '|', '\"' }, { '_', '\"' }, { ',', 0 }, - { '|', 0 }, { '\t', 0 } }; - - /** - * Test without any line breaks - * - */ - public void testNoLineBreaks() { - // loop down all delimiter qualifier pairs to test - for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { - final char d = DELIM_QUAL_PAIR[i][0]; - final char q = DELIM_QUAL_PAIR[i][1]; - - final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_NO_BREAKS, d, q); - - final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, d, q, 10); - - // check to make sure we have the same amount of elements which were - // expected - assertEquals("Expected size (d = [" + d + "] q = [" + (q != 0 ? String.valueOf(q) : "") + "] txt [" + txtToParse - + "])", DELIMITED_DATA_NO_BREAKS.length, splitLineResults.size()); - - // loop through each value and compare what came back - for (int j = 0; j < DELIMITED_DATA_NO_BREAKS.length; j++) { - assertEquals("Data Element Value Does Not Match (d = [" + d + "] q = [" + q + "] txt [" + txtToParse + "])", - DELIMITED_DATA_NO_BREAKS[j], (String) splitLineResults.get(j)); - } - } - - } - - /** - * Test with any line breaks - * - */ - public void testLineBreaks() { - // loop down all delimiter qualifier pairs to test - for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { - final char d = DELIM_QUAL_PAIR[i][0]; - final char q = DELIM_QUAL_PAIR[i][1]; - - final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_WITH_BREAKS, d, q); - - final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, d, q, 10); - - // check to make sure we have the same amount of elements which were - // expected - assertEquals("Did Not Get Amount Of Elements Expected (d = " + d + " q = " + q + ")", - DELIMITED_DATA_WITH_BREAKS.length, splitLineResults.size()); - - // loop through each value and compare what came back - for (int j = 0; j < DELIMITED_DATA_WITH_BREAKS.length; j++) { - assertEquals("Data Element Value Does Not Match (d = " + d + " q = " + q + ")", DELIMITED_DATA_WITH_BREAKS[j], - (String) splitLineResults.get(j)); - } - } - } - - /** - * Test to make sure we get the correct amount of elements for malformed - * data - */ - public void testMalformedData() { - final List splitLineResults = BXParser.splitLineWithBuf(DELIMITED_BAD_DATA, ',', '\"', 10); - - assertEquals("Expecting 2 Data Elements From The Malformed Data", 2, splitLineResults.size()); - } - - /** - * Test some extreme cases - */ - public void testSomeExtremeCases() { - check(null, ',', '\"', new String[] {}); - check("a", ',', '\"', new String[] { "a" }); - check("", ',', '\"', new String[] { "" }); - check(" ", ',', '\"', new String[] { "" }); - check(" ", ',', '\"', new String[] { "" }); - check(",", ',', '\"', new String[] { "", "" }); - check(",,", ',', '\"', new String[] { "", "", "" }); - check(",a,", ',', '\"', new String[] { "", "a", "" }); - - check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); - check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); - check("\"a , b\",\"c\"", ',', '\"', new String[] { "a , b", "c" }); - check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); - check("a b,c", ',', '\"', new String[] { "a b", "c" }); - check(" a,b,c ", ',', '\"', new String[] { "a", "b", "c" }); - check(" a, b ,c", ',', '\"', new String[] { "a", "b", "c" }); - - // example typically from Excel. - check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\"', new String[] { "test1", "test2", "0.00", - "another, element here", "lastone" }); - - check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); - check(" a, b ,c ", ',', '\"', new String[] { "a", "b", "c" }); - check("\"a\", b , \"c\"", ',', '\"', new String[] { "a", "b", "c" }); - - check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", "", "", "", "last one" }); - check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", "" }); - check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); - check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); - check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); - - check("one two three", ' ', '\u0000', new String[] {"one", "two", "three"}); - check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "two", "three"}); - check("\"one\" \"two\" three", ' ', '\"', new String[] {"one", "", "two", "", "three"}); - } - - private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { - final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, delim, qualifier, 10); - - assertEquals( - "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", - expected.length, splitLineResults.size()); - - for (int i = 0; i < expected.length; i++) { - assertEquals("expecting...", expected[i], splitLineResults.get(i)); - } - } - - public static void main(final String[] args) { - junit.textui.TestRunner.run(BXParserTest.class); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 17:16:58
|
Revision: 192 http://svn.sourceforge.net/pzfilereader/?rev=192&view=rev Author: zepernick Date: 2006-11-25 09:16:58 -0800 (Sat, 25 Nov 2006) Log Message: ----------- removed class which was not really a test Removed Paths: ------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/multiline/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 15:54:19
|
Revision: 191 http://svn.sourceforge.net/pzfilereader/?rev=191&view=rev Author: zepernick Date: 2006-11-25 07:54:19 -0800 (Sat, 25 Nov 2006) Log Message: ----------- added some unit tests for pzconverter Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsTest.java 2006-11-25 15:53:52 UTC (rev 190) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsTest.java 2006-11-25 15:54:19 UTC (rev 191) @@ -1,6 +1,9 @@ package net.sf.pzfilereader.parserutils; +import java.io.IOException; +import java.math.BigDecimal; import java.util.List; +import java.util.Properties; import net.sf.pzfilereader.util.ParserUtils; import junit.framework.TestCase; @@ -44,6 +47,14 @@ final String stripRes = ParserUtils.stripNonLongChars(txtToStrip); assertEquals("expecting...", stripRes, expected); } + + public void testPZConverter() throws IOException{ + final Properties convertProps = ParserUtils.loadConvertProperties(); + + assertEquals(ParserUtils.runPzConverter(convertProps, "$5.00C", Double.class), new Double("5.00")); + assertEquals(ParserUtils.runPzConverter(convertProps, "$5.00C", Integer.class), new Integer("5")); + assertEquals(ParserUtils.runPzConverter(convertProps, "$5.3556", BigDecimal.class), new BigDecimal("5.3556")); + } public static void main(final String[] args) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |