/**
* @see org.springframework.batch.item.ItemReader#read()
*/
@Override
public Trade read() throws Exception {
Trade t = null;
for (FieldSet line; (line = this.delegate.read()) != null;) {
String prefix = line.readString(0);
if (prefix.equals("BEGIN")) {
t = new Trade(); // Record must start with 'BEGIN'
}
else if (prefix.equals("INFO")) {
Assert.notNull(t, "No 'BEGIN' was found.");
t.setIsin(line.readString(1));
t.setCustomer(line.readString(2));
}
else if (prefix.equals("AMNT")) {
Assert.notNull(t, "No 'BEGIN' was found.");
t.setQuantity(line.readInt(1));
t.setPrice(line.readBigDecimal(2));
}
else if (prefix.equals("END")) {
return t; // Record must end with 'END'
}
}