*/
protected String convertTemplateToInput(String templateFileName, String inputFileName,
TemplateListener... listeners) throws DataAccessObjectException {
String fileName = new File(getTestDataDir(), templateFileName).getAbsolutePath();
final CSVFileReader templateReader = new CSVFileReader(fileName, getController());
try {
templateReader.open();
int numRows = templateReader.getTotalRows();
final List<Row> templateRows = templateReader.readRowList(numRows);
assertNotNull("CVSReader returned a null list of rows, but expected a list with size " + numRows,
templateRows);
final List<Row> inputRows = new ArrayList<Row>(templateRows.size());
// verify that the template file is useable
assertEquals("Wrong number of rows were read using readRowList while attempting to convert template file: "
+ templateFileName, numRows, templateRows.size());
// insert accounts for the whole template or part of it if
// maxInserts is smaller then template size
int idx = 0;
for (Row templateRow : templateRows) {
final Row row = new Row(templateRow);
if (listeners != null) {
for (TemplateListener l : listeners) {
l.updateRow(idx, row);
}
}
inputRows.add(row);
idx++;
}
final String inputPath = new File(getTestDataDir(), inputFileName).getAbsolutePath();
final CSVFileWriter inputWriter = new CSVFileWriter(inputPath, getController().getConfig());
try {
inputWriter.open();
inputWriter.setColumnNames(templateReader.getColumnNames());
inputWriter.writeRowList(inputRows);
return inputPath;
} finally {
inputWriter.close();
}
} finally {
templateReader.close();
}
}