outputStream.write(bytesCRLF);
}
}
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
BindyFixedLengthFactory factory = (BindyFixedLengthFactory) getFactory(exchange.getContext().getPackageScanClassResolver());
ObjectHelper.notNull(factory, "not instantiated");
// List of Pojos
List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
// Pojos of the model
Map<String, Object> model;
InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
// Scanner is used to read big file
Scanner scanner = new Scanner(in);
int count = 0;
try {
// TODO Test if we have a Header
// TODO Test if we have a Footer (containing by example checksum)
while (scanner.hasNextLine()) {
String line;
// Read the line (should not trim as its fixed length)
line = scanner.nextLine();
if (ObjectHelper.isEmpty(line)) {
// skip if line is empty
continue;
}
// Increment counter
count++;
// Check if the record length corresponds to the parameter
// provided in the @FixedLengthRecord
if ((line.length() < factory.recordLength()) || (line.length() > factory.recordLength())) {
throw new java.lang.IllegalArgumentException("Size of the record: " + line.length() + " is not equal to the value provided in the model: " + factory.recordLength());
}
// Create POJO where Fixed data will be stored
model = factory.factory();
// Bind data from Fixed record with model classes
factory.bind(line, model, count);
// Link objects together
factory.link(model);
// Add objects graph to the list
models.add(model);
LOG.debug("Graph of objects created: {}", model);