use of org.apache.camel.converter.PurchaseOrder in project camel by apache.
the class PurchaseOrderConverter method toPurchaseOrder.
@Converter
public PurchaseOrder toPurchaseOrder(byte[] data) {
String s = converter.convertTo(String.class, data);
if (s == null || s.length() < 30) {
throw new IllegalArgumentException("data is invalid");
}
s = s.replaceAll("##START##", "");
s = s.replaceAll("##END##", "");
String name = s.substring(0, 9).trim();
String s2 = s.substring(10, 19).trim();
String s3 = s.substring(20).trim();
BigDecimal price = new BigDecimal(s2);
price = price.setScale(2);
Integer amount = converter.convertTo(Integer.class, s3);
PurchaseOrder order = new PurchaseOrder(name, price, amount);
return order;
}
Aggregations