}
}
while (!inFile.eof())
{
Record record = inFile.get();
String line = "";
recordCount++;
fieldCount = 0;
if (outputFieldNamesWrite) {
if (outputFields.isEmpty()) {
for(int i=0; i<record.field_count(); i++) {
if (i>0) line += this.getOutputFieldSeparator();
line += record.field_name(i);
}
} else {
Iterator it = outputFields.iterateKeys();
int itCount = 0;
while(it.hasNext()) {
if (itCount>0) line += this.getOutputFieldSeparator();
line += (String) it.next();
itCount++;
}
}
outFile.put_line(line);
line = "";
outputFieldNamesWrite = false;
}
// should no output fields have been found, then use them from the first ecord
if (outputFields.isEmpty() && recordCount == 1) {
for(int i=0; i<record.field_count(); i++) {
outputFields.put(record.field_name(i).toLowerCase(), "string");
}
}
try {
int outputFieldCount = 0;
Iterator it = outputFields.iterateKeys();
while(it.hasNext()) {
fieldName = (String) it.next();
fieldCount++;
if (record.string(fieldName) != null && record.string(fieldName).length() > 0) {
String fieldType = (String) outputFields.get(fieldName.toLowerCase());
if (fieldType != null && fieldType.toLowerCase().equals("string")) {
if (this.getOutputFieldDelimiterQuote().length() > 0) {
if (outputFieldCount>0) line += this.getOutputFieldSeparator();
line += this.getOutputFieldDelimiter() + record.string(fieldName).replaceAll("\\" + this.getOutputFieldDelimiter(), this.getOutputFieldDelimiterQuote() + this.getOutputFieldDelimiter()) + this.getOutputFieldDelimiter();
outputFieldCount++;
} else {
if (outputFieldCount>0) line += this.getOutputFieldSeparator();
line += this.getOutputFieldDelimiter() + record.string(fieldName) + this.getOutputFieldDelimiter();
outputFieldCount++;
}
} else if (fieldType != null && fieldType.toLowerCase().indexOf("date") > -1) {
try {
if (outputFieldCount>0) line += this.getOutputFieldSeparator();
// line += this.getOutputFieldDelimiter() + SOSDate.getDateAsString(SOSDate.getDate(record.string(fieldName), SOSDate.dateTimeFormat), this.getOutputDateFormat()) + this.getOutputFieldDelimiter();
line += this.getOutputFieldDelimiter() + SOSDate.getDateAsString(SOSDate.getDate(record.string(fieldName), this.getInputDateFormat()), this.getOutputDateFormat()) + this.getOutputFieldDelimiter();
outputFieldCount++;
} catch (Exception e) {
throw new Exception("could not convert date using output date format [" + this.getOutputDateFormat() + "]: " + record.string(fieldName));
}
} else if (fieldType == null || fieldType.length() == 0) {
// skip record
} else {
throw new Exception("unsupported field type specified for field [" + fieldName + "]: " + fieldType);