本文整理汇总了Java中net.sf.flatpack.DefaultParserFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultParserFactory类的具体用法?Java DefaultParserFactory怎么用?Java DefaultParserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultParserFactory类属于net.sf.flatpack包,在下文中一共展示了DefaultParserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String mapping, final String data) throws Exception {
// wll provide a clean format for printing the date to the screen
final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '\"', true);
final DataSet ds = pzparser.parse();
// demonstrates the casting abilities of FlatPack
while (ds.next()) {
System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)");
System.out.println("In Stock: " + ds.getInt("IN_STOCK") + " (int)");
System.out.println("Price: " + ds.getDouble("PRICE") + " (double)");
System.out.println("Received Dt: " + sdf.format(ds.getDate("LAST_RECV_DT")) + " (Date)");
System.out.println("===========================================================================");
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:19,代码来源:NumericsAndDates.java
示例2: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String data) throws Exception {
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(data), ',', '\"');
final DataSet ds = pzparser.parse();
final String[] colNames = ds.getColumns();
while (ds.next()) {
for (final String colName : colNames) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName));
}
System.out.println("===========================================================================");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE");
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:23,代码来源:DelimitedMultiLine.java
示例3: testMultipleLine
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testMultipleLine() throws Exception {
final DelimiterWriterFactory factory = new DelimiterWriterFactory(mapping, ',', '"');
final StringWriter strWriter = new StringWriter();
final Writer flatMapWriter = factory.createWriter(strWriter, new WriterOptions().autoPrintHeader(false));
flatMapWriter.printHeader();
flatMapWriter.addRecordEntry("Id", "1");
flatMapWriter.addRecordEntry("Description", CONTENT);
flatMapWriter.nextRecord();
flatMapWriter.flush();
flatMapWriter.close();
LOG.info("CSV is \n{}", strWriter.toString());
final String toRead = strWriter.toString();
final DataSet ds = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(toRead), ',', '"').parse();
if (ds.next()) {
LOG.info("Parsed content \n{}", ds.getString("Description"));
assertEquals(ds.getString("Description"), CONTENT);
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:22,代码来源:MultiLineTest.java
示例4: testHandleShortLines
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testHandleShortLines() {
DataSet ds;
final String cols = "COLUMN1,column2,Column3\r\n value1";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setHandlingShortLines(true);
// p.setIgnoreParseWarnings(true);
ds = p.parse();
assertEquals("Should have a row of data", true, ds.next());
// re-test the buffered reader
p = BuffReaderParseFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setHandlingShortLines(true);
// p.setIgnoreParseWarnings(true);
ds = p.parse();
assertEquals("Should have a row of data", true, ds.next());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:17,代码来源:PZParserOptsTest.java
示例5: testIgnoreExtraColumns
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testIgnoreExtraColumns() {
DataSet ds;
final String cols = "COLUMN1,column2,Column3\r\n \"value1\",value2,value3,value4";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', '"');
p.setIgnoreExtraColumns(true);
// p.setIgnoreParseWarnings(true);
ds = p.parse();
assertEquals("Should have a row of data", true, ds.next());
// re-test the buffered reader
p = BuffReaderParseFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', '"');
p.setIgnoreExtraColumns(true);
// p.setIgnoreParseWarnings(true);
ds = p.parse();
assertEquals("Should have a row of data", true, ds.next());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:17,代码来源:PZParserOptsTest.java
示例6: testEmptyToNull
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testEmptyToNull() {
DataSet ds;
final String cols = "COLUMN1,column2,Column3\r\n value1,,value3";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setNullEmptyStrings(true);
ds = p.parse();
ds.next();
assertEquals("String should be null...", null, ds.getString("column2"));
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setNullEmptyStrings(false);
ds = p.parse();
ds.next();
assertEquals("String should be empty...", "", ds.getString("column2"));
}
开发者ID:Appendium,项目名称:flatpack,代码行数:18,代码来源:PZParserOptsTest.java
示例7: testIgnoreWarnings
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testIgnoreWarnings() {
DataSet ds;
final String cols = "COLUMN1,column2,Column3\r\n value1,value2";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setHandlingShortLines(true);
p.setIgnoreParseWarnings(true);
ds = p.parse();
assertEquals("Error collection should be empty...", 0, ds.getErrors().size());
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setHandlingShortLines(true);
p.setIgnoreParseWarnings(false);
ds = p.parse();
ds.next();
assertEquals("Error collection should contain warning...", 1, ds.getErrors().size());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:19,代码来源:PZParserOptsTest.java
示例8: testEmptyRowCheck
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testEmptyRowCheck() {
DataSet ds;
final String cols = "column1,column2,column3\r\n,,";
// check to see if the flag empty rows works
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setFlagEmptyRows(true);
ds = p.parse();
ds.next();
assertEquals("Row should return empty...", ds.isRowEmpty(), true);
// do not set to flag empty rows, but make the check anyhow to make sure we get an exception
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
ds = p.parse();
ds.next();
try {
ds.isRowEmpty();
fail("should have got FPInvalidUsageException...");
} catch (final FPInvalidUsageException e) {
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:23,代码来源:PZParserOptsTest.java
示例9: testStoreRawDataToDataError
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testStoreRawDataToDataError() {
DataSet ds;
final String cols = "column1,column2,column3\r\nVAL1,VAL2,VAL3,VAL4";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setStoreRawDataToDataError(true);
ds = p.parse();
Iterator errors = ds.getErrors().iterator();
DataError de = (DataError) errors.next();
assertNotNull("DataError should contain line data...", de.getRawData());
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setStoreRawDataToDataError(false);
ds = p.parse();
errors = ds.getErrors().iterator();
de = (DataError) errors.next();
assertNull("DataError should have <null> line data...", de.getRawData());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:19,代码来源:PZParserOptsTest.java
示例10: testStoreRawData
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testStoreRawData() {
DataSet ds;
final String cols = "column1,column2,column3\r\nVAL1,VAL2,VAL3";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
p.setStoreRawDataToDataSet(true);
ds = p.parse();
ds.next();
assertEquals("VAL1,VAL2,VAL3", ds.getRawData());
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
ds = p.parse();
ds.next();
try {
ds.getRawData();
fail("Should have received an FPExcpetion...");
} catch (final FPInvalidUsageException e) {
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:20,代码来源:PZParserOptsTest.java
示例11: testEmptyLastColumn
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testEmptyLastColumn() {
// this was reported as a bug in the forums check to see
// if we actually have a problem
DataSet ds;
String cols = "column1,column2,column3\r\nVAL1,VAL2,";
Parser p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', FPConstants.NO_QUALIFIER);
ds = p.parse();
assertEquals(true, ds.next());
cols = "column1,column2,column3\r\n\"VAL1\",\"VAL2\",\"\"";
p = DefaultParserFactory.getInstance().newDelimitedParser(new StringReader(cols), ',', '"');
ds = p.parse();
assertEquals(true, ds.next());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:17,代码来源:PZParserOptsTest.java
示例12: testFixedWidthMultipleRecordElementsInMapping
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public void testFixedWidthMultipleRecordElementsInMapping() {
DataSet ds;
final String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n" + "<!DOCTYPE PZMAP SYSTEM \"pzfilereader.dtd\" > \r\n"
+ " <PZMAP>\r\n" + " <RECORD id=\"header\" startPosition=\"1\" endPosition=\"1\" indicator=\"H\">"
+ " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + " <COLUMN name=\"headerdata1\" length=\"20\" /> \r\n" + " </RECORD>"
+ " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + " <COLUMN name=\"detaildata1\" length=\"20\" /> \r\n" + " </PZMAP>";
final String cols = "HHEADER DATA \r\n" + "DDETAIL DATA \r\n";
final Parser p = DefaultParserFactory.getInstance().newFixedLengthParser(new StringReader(xml), new StringReader(cols));
ds = p.parse();
int i = 0;
while (ds.next()) {
if (i == 0) {
assertEquals("Checking to see if we have the header record...", ds.isRecordID("header"), true);
assertEquals("Checking header data", ds.getString("headerdata1"), "HEADER DATA");
} else {
assertEquals("Checking detail data", ds.getString("detaildata1"), "DETAIL DATA");
}
i++;
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:25,代码来源:PZParserOptsTest.java
示例13: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String mapping, final String data) throws Exception {
final File mapFile = new File(mapping);
final File dataFile = new File(data);
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(mapFile, dataFile, ',', '\"', true);
final DataSet ds = pzparser.parse();
while (ds.next()) {
if (ds.isRecordID("header")) {
System.out.println(">>>>>>Found Header Record");
System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA"));
System.out.println("===========================================================================");
continue;
}
if (ds.isRecordID("trailer")) {
System.out.println(">>>>>>Found Trailer Record");
System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA"));
System.out.println("===========================================================================");
continue;
}
System.out.println("COLUMN NAME: FIRSTNAME VALUE: " + ds.getString("FIRSTNAME"));
System.out.println("COLUMN NAME: LASTNAME VALUE: " + ds.getString("LASTNAME"));
System.out.println("COLUMN NAME: ADDRESS VALUE: " + ds.getString("ADDRESS"));
System.out.println("COLUMN NAME: CITY VALUE: " + ds.getString("CITY"));
System.out.println("COLUMN NAME: STATE VALUE: " + ds.getString("STATE"));
System.out.println("COLUMN NAME: ZIP VALUE: " + ds.getString("ZIP"));
System.out.println("===========================================================================");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE");
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:40,代码来源:CSVHeaderAndTrailer.java
示例14: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String mapping, final String data) throws Exception {
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), ',', '"', true);
final DataSet ds = pzparser.parse();
// re order the data set by last name
final OrderBy orderby = new OrderBy();
orderby.addOrderColumn(new OrderColumn("CITY", false));
orderby.addOrderColumn(new OrderColumn("LASTNAME", true));
ds.orderRows(orderby);
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
for (int i = 0; i < ds.getErrors().size(); i++) {
final DataError de = (DataError) ds.getErrors().get(i);
System.out.println("Error Msg: " + de.getErrorDesc() + " Line: " + de.getLineNo());
}
}
// lets write this file out to excel
final File xlFile = new File("MyExcelExport.xls");
final ExcelTransformer xlTransformer = new ExcelTransformer(ds, xlFile);
xlTransformer.writeExcelFile();
System.out.println("Excel Workbook Written To: " + xlFile.getAbsolutePath());
}
开发者ID:Appendium,项目名称:flatpack,代码行数:28,代码来源:DelimitedFileExportToExcel.java
示例15: main
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
String[] colNames = null;
OrderBy orderby = null;
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"');
final DataSet ds = pzparser.parse();
// re order the data set by last name
orderby = new OrderBy();
orderby.addOrderColumn(new OrderColumn("CITY", false));
orderby.addOrderColumn(new OrderColumn("LASTNAME", true));
ds.orderRows(orderby);
colNames = ds.getColumns();
while (ds.next()) {
for (final String colName : colNames) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName));
}
System.out.println("===========================================================================");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE....");
for (int i = 0; i < ds.getErrors().size(); i++) {
final DataError de = (DataError) ds.getErrors().get(i);
System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo());
}
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:36,代码来源:DelimitedColumnNamesInFile.java
示例16: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String mapping, final String data) throws Exception {
final Parser pzparser = DefaultParserFactory.getInstance().newFixedLengthParser(new File(mapping), new File(data));
final DataSet ds = pzparser.parse();
final String[] colNames = ds.getColumns();
while (ds.next()) {
for (final String colName : colNames) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName));
}
System.out.println("===========================================================================");
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:16,代码来源:FixedLengthWithPZMap.java
示例17: main
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
String[] colNames = null;
File tmpFile = null;
// delimited by a comma
// text qualified by double quotes
// ignore first record
tmpFile = new File("net/sf/flatpack/delim/tab/PEOPLE-TabDelimitedWithQualifier.txt");
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(tmpFile, '\t', '\"');
final DataSet ds = pzparser.parse();
// re order the data set by last name
/*
* orderby = new OrderBy(); orderby.addOrderColumn(new
* OrderColumn("CITY",false)); orderby.addOrderColumn(new
* OrderColumn("LASTNAME",true)); ds.orderRows(orderby);
*/
colNames = ds.getColumns();
while (ds.next()) {
for (final String colName : colNames) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName));
}
System.out.println("===========================================================================");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE....");
for (int i = 0; i < ds.getErrors().size(); i++) {
final DataError de = (DataError) ds.getErrors().get(i);
System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo());
}
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:38,代码来源:TabDelimited.java
示例18: main
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
String[] colNames = null;
OrderBy orderby = null;
// delimited by a comma
// text qualified by double quotes
// ignore first record
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(
new File("net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"');
final DataSet ds = pzparser.parse();
// re order the data set by last name
orderby = new OrderBy();
orderby.addOrderColumn(new OrderColumn("CITY", false));
orderby.addOrderColumn(new OrderColumn("LASTNAME", true));
ds.orderRows(orderby);
colNames = ds.getColumns();
while (ds.next()) {
for (final String colName : colNames) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + ds.getString(colName));
}
System.out.println("===========================================================================");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE....");
for (int i = 0; i < ds.getErrors().size(); i++) {
final DataError de = (DataError) ds.getErrors().get(i);
System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo());
}
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:37,代码来源:DelimitedColumnNamesInFile.java
示例19: getDsForTest
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public DataSet getDsForTest() throws Exception {
final Parser parser = DefaultParserFactory.getInstance().newDelimitedParser(
new File("src/test/java/net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '\"');
return parser.parse();
// return new DataSet(new
// File("src/test/java/net/sf/flatpack/columninfile/PEOPLE-CommaDelimitedWithQualifier.txt"),
// ",",
// "\"", false);
}
开发者ID:Appendium,项目名称:flatpack,代码行数:13,代码来源:DelimitedColumnNamesInFile.java
示例20: call
import net.sf.flatpack.DefaultParserFactory; //导入依赖的package包/类
public static void call(final String filename, final boolean verbose, final boolean traverse) throws Exception, InterruptedException {
String[] colNames = null;
// delimited by a comma
// text qualified by double quotes
// ignore first record
System.out.println("Parsing....");
final Parser pzparser = DefaultParserFactory.getInstance().newDelimitedParser(new File(filename), ',', '"');
long timeStarted = System.currentTimeMillis();
final DataSet ds = pzparser.parse();
long timeFinished = System.currentTimeMillis();
String timeMessage = "";
if (timeFinished - timeStarted < 1000) {
timeMessage = timeFinished - timeStarted + " Milleseconds...";
} else {
timeMessage = (float) ((timeFinished - timeStarted) / 1000.0) + " Seconds...";
}
System.out.println("");
System.out.println("********FILE PARSED IN: " + timeMessage + " ******");
if (traverse) {
if (verbose) {
Thread.sleep(2000); // sleep for a couple seconds to the message
// above can be read
}
timeStarted = System.currentTimeMillis();
colNames = ds.getColumns();
int rowCount = 0;
final int colCount = colNames.length;
while (ds.next()) {
rowCount++;
for (final String colName : colNames) {
final String string = ds.getString(colName);
if (verbose) {
System.out.println("COLUMN NAME: " + colName + " VALUE: " + string);
}
}
if (verbose) {
System.out.println("===========================================================================");
}
}
timeFinished = System.currentTimeMillis();
if (timeFinished - timeStarted < 1000) {
timeMessage = timeFinished - timeStarted + " Milleseconds...";
} else {
timeMessage = (float) ((timeFinished - timeStarted) / 1000.0) + " Seconds...";
}
System.out.println("");
System.out.println("********Traversed Data In: " + timeMessage + " (rows: " + rowCount + " Col:" + colCount + ") ******");
}
if (ds.getErrors() != null && !ds.getErrors().isEmpty()) {
System.out.println("FOUND ERRORS IN FILE....");
for (int i = 0; i < ds.getErrors().size(); i++) {
final DataError de = (DataError) ds.getErrors().get(i);
System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo());
}
}
}
开发者ID:Appendium,项目名称:flatpack,代码行数:68,代码来源:CSVPerformanceTest.java
注:本文中的net.sf.flatpack.DefaultParserFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论