本文整理汇总了Java中net.sf.flatpack.DefaultParserFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultParserFactory类的具体用法?Java DefaultParserFactory怎么用?Java DefaultParserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultParserFactory类属于net.sf.flatpack包,在下文中一共展示了DefaultParserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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("===========================================================================");
}
}
示例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");
}
}
示例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);
}
}
示例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());
}
示例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());
}
示例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"));
}
示例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());
}
示例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) {
}
}
示例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());
}
示例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) {
}
}
示例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());
}
示例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++;
}
}
示例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");
}
}
示例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());
}
示例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());
}
}
}