BATCH-1418: Added jumpToItem implementation in FFIR to all for correct restart

This commit is contained in:
lucasward
2009-09-30 04:50:33 +00:00
parent a6dd427f93
commit 172506250e

View File

@@ -163,24 +163,15 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
if (noInput) {
return null;
}
String line = readLine();
String record = line;
if (line != null) {
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
line = readLine();
if (line==null) {
throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount);
}
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);
return lineMapper.mapLine(line, lineCount);
}
catch(Exception ex){
logger.error("Parsing error at line: " + lineCount + " in resource=" +
@@ -200,13 +191,13 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
}
String line = null;
try {
line = this.reader.readLine();
if (line == null) {
return null;
}
lineCount++;
while (isComment(line)) {
line = reader.readLine();
if (line == null) {
@@ -214,12 +205,30 @@ 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);
}
return line;
}
private String applyRecordSeparatorPolicy(String line) throws IOException{
String record = line;
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
line = this.reader.readLine();
if (line==null) {
throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount);
}
record = recordSeparatorPolicy.preProcess(record) + line;
lineCount++;
}
return recordSeparatorPolicy.postProcess(record);
}
private boolean isComment(String line) {
for (String prefix : comments) {
@@ -261,6 +270,13 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
}
}
}
@Override
protected void jumpToItem(int itemIndex) throws Exception {
for (int i = 0; i < itemIndex; i++) {
readLine();
}
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(lineMapper, "LineMapper is required");