Continue after an error
/*
* Copyright (c) 2006-2008 North Concepts Inc. All rights reserved.
* Proprietary and Confidential. Use is subject to license terms.
*
* http://northconcepts.com/data-pipeline/licensing/
*
*/
package com.northconcepts.datapipeline.examples.cookbook;
import java.io.File;
import org.apache.log4j.Logger;
import com.northconcepts.datapipeline.core.DataEndpoint;
import com.northconcepts.datapipeline.core.DataException;
import com.northconcepts.datapipeline.core.Record;
import com.northconcepts.datapipeline.csv.CSVReader;
public class ContinueAfterAnError {
public static final Logger log = DataEndpoint.log;
public static void main(String[] args) {
// open a CSV file with an error in the second record (unterminated quote)
CSVReader csvReader = new CSVReader(new File("bad-credit-balance.csv")) {
// override CSVReader.read() to ignore exceptions
public Record read() throws DataException {
try {
return super.read();
} catch (DataException e) {
e.printStackTrace();
return read();
}
}
};
csvReader.setFieldNamesInFirstRow(true);
csvReader.open();
try {
Record record;
while ((record = csvReader.read()) != null) {
log.debug(record);
}
} finally {
csvReader.close();
}
}
}
back to examples index
|