BATCH-1423: Merged FlatFileItemReader from 2.0.x into trunk
This commit is contained in:
@@ -177,35 +177,19 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
|
||||
if (noInput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String line = readLine();
|
||||
String record = line;
|
||||
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
|
||||
line = readLine();
|
||||
if (line == null) {
|
||||
if (StringUtils.hasText(record)) {
|
||||
// A record was partially complete since it hasn't ended but
|
||||
// the line is null
|
||||
throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount);
|
||||
}
|
||||
else {
|
||||
// Record has no text but it might still be post processed
|
||||
// to something (skipping preProcess since that was already done)
|
||||
break;
|
||||
}
|
||||
}
|
||||
record = recordSeparatorPolicy.preProcess(record) + line;
|
||||
}
|
||||
String logicalLine = recordSeparatorPolicy.postProcess(record);
|
||||
if (logicalLine == null) {
|
||||
|
||||
if (line == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return lineMapper.mapLine(logicalLine, lineCount);
|
||||
try{
|
||||
return lineMapper.mapLine(line, lineCount);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("Parsing error at line: " + lineCount + " in resource=" + resource.getDescription()
|
||||
+ ", input=[" + line + "]", ex);
|
||||
catch(Exception ex){
|
||||
logger.error("Parsing error at line: " + lineCount + " in resource=" +
|
||||
resource.getDescription() + ", input=[" + line + "]", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -235,6 +219,8 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
|
||||
}
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
line = applyRecordSeparatorPolicy(line);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new FlatFileParseException("Unable to read from resource: [" + resource + "]", e, line, lineCount);
|
||||
@@ -286,5 +272,39 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(lineMapper, "LineMapper is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void jumpToItem(int itemIndex) throws Exception {
|
||||
for (int i = 0; i < itemIndex; i++) {
|
||||
readLine();
|
||||
}
|
||||
}
|
||||
|
||||
private String applyRecordSeparatorPolicy(String line) throws IOException{
|
||||
|
||||
String record = line;
|
||||
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
|
||||
line = this.reader.readLine();
|
||||
if (line == null) {
|
||||
if (StringUtils.hasText(record)) {
|
||||
// A record was partially complete since it hasn't ended but
|
||||
// the line is null
|
||||
throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount);
|
||||
}
|
||||
else {
|
||||
// Record has no text but it might still be post processed
|
||||
// to something (skipping preProcess since that was already done)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
lineCount++;
|
||||
}
|
||||
record = recordSeparatorPolicy.preProcess(record) + line;
|
||||
}
|
||||
|
||||
return recordSeparatorPolicy.postProcess(record);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user