BATCH-1417: fixed in 2.0.x as well

This commit is contained in:
dsyer
2009-09-28 16:54:53 +00:00
parent 9e535018ae
commit a6dd427f93
2 changed files with 42 additions and 1 deletions

View File

@@ -167,7 +167,11 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
String record = line;
if (line != null) {
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
record = recordSeparatorPolicy.preProcess(record) + (line = readLine());
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);

View File

@@ -70,6 +70,43 @@ public class FlatFileItemReaderTests {
assertEquals("testLine5testLine6", reader.read());
}
@Test
public void testCustomRecordSeparatorPolicyEndOfFile() throws Exception {
reader.setRecordSeparatorPolicy(new RecordSeparatorPolicy() {
// 1 record = 2 lines
boolean pair = true;
public boolean isEndOfRecord(String line) {
pair = !pair;
return pair;
}
public String postProcess(String record) {
return record;
}
public String preProcess(String record) {
return record;
}
});
reader.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\n"));
reader.open(executionContext);
assertEquals("testLine1testLine2", reader.read());
try {
reader.read();
fail("Expected Exception");
} catch (FlatFileParseException e) {
// File ends in the middle of a record
assertEquals(3, e.getLineNumber());
assertEquals("testLine3", e.getInput());
}
}
@Test
public void testRestartWithSkippedLines() throws Exception {