本文整理汇总了Java中net.sf.flatpack.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.parse方法的具体用法?Java Parser.parse怎么用?Java Parser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.flatpack.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import net.sf.flatpack.Parser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
Parser parser = endpoint.createParser(exchange);
DataSet dataSet = parser.parse();
if (dataSet.getErrorCount() > 0) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("Flatpack has found %s errors while parsing", dataSet.getErrorCount()));
throw new FlatpackException(sb.toString(), exchange, dataSet.getErrors());
}
if (endpoint.isSplitRows()) {
int counter = 0;
while (dataSet.next()) {
endpoint.processDataSet(exchange, dataSet, counter++);
}
} else {
endpoint.processDataSet(exchange, dataSet, dataSet.getRowCount());
}
}
示例2: testFixedWidthMultipleRecordElementsInMapping
import net.sf.flatpack.Parser; //导入方法依赖的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++;
}
}
示例3: testEmptyLastColumn
import net.sf.flatpack.Parser; //导入方法依赖的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());
}
示例4: call
import net.sf.flatpack.Parser; //导入方法依赖的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");
}
}
示例5: testStoreRawData
import net.sf.flatpack.Parser; //导入方法依赖的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) {
}
}
示例6: testHandleShortLines
import net.sf.flatpack.Parser; //导入方法依赖的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());
}
示例7: testIgnoreExtraColumns
import net.sf.flatpack.Parser; //导入方法依赖的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());
}
示例8: testEmptyToNull
import net.sf.flatpack.Parser; //导入方法依赖的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"));
}
示例9: testIgnoreWarnings
import net.sf.flatpack.Parser; //导入方法依赖的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());
}
示例10: testEmptyRowCheck
import net.sf.flatpack.Parser; //导入方法依赖的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) {
}
}
示例11: testStoreRawDataToDataError
import net.sf.flatpack.Parser; //导入方法依赖的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());
}
示例12: unmarshal
import net.sf.flatpack.Parser; //导入方法依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
InputStreamReader reader = new InputStreamReader(stream, IOHelper.getCharsetName(exchange));
try {
Parser parser = createParser(exchange, reader);
DataSet dataSet = parser.parse();
return new DataSetList(dataSet);
} finally {
reader.close();
}
}
示例13: call
import net.sf.flatpack.Parser; //导入方法依赖的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.Parser; //导入方法依赖的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.Parser; //导入方法依赖的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());
}
}
}