Fuse 6 is no longer supportedAs of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.
2.9. Configuring Fixed-Length Records
To bind fixed-length records to a person, see the configuration below. In this example we will use these sample records:
Tom Fennelly M 21 IE
Maurice Zeijen M 27 NL
Tom Fennelly M 21 IE
Maurice Zeijen M 27 NL
Copy to ClipboardCopied!Toggle word wrapToggle overflow
This is how you bind them to a person:
public class Person {
private String firstname;
private String lastname;
private String country;
private String gender;
private int age;
}
public class Person {
private String firstname;
private String lastname;
private String country;
private String gender;
private int age;
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Configure the records so they look like this:
<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="firstname[10]?trim,lastname[10]?trim,gender[1],age[3]?trim,country[2]">
<!-- Note how the field names match the property names on the Person class. -->
<fl:listBinding BeanId="people" class="org.milyn.fixedlength.Person" />
</fl:reader>
</smooks-resource-list>
<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="firstname[10]?trim,lastname[10]?trim,gender[1],age[3]?trim,country[2]">
<!-- Note how the field names match the property names on the Person class. -->
<fl:listBinding BeanId="people" class="org.milyn.fixedlength.Person" />
</fl:reader>
</smooks-resource-list>
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Execute it as shown:
Smooks smooks = new Smooks(configStream);
JavaResult result = new JavaResult();
smooks.filterSource(new StreamSource(fixedLengthStream), result);
List<Person> people = (List<Person>) result.getBean("people");
Smooks smooks = new Smooks(configStream);
JavaResult result = new JavaResult();
smooks.filterSource(new StreamSource(fixedLengthStream), result);
List<Person> people = (List<Person>) result.getBean("people");
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Optionally, use this configuration to create maps from the fixed-length record set:
Copy to ClipboardCopied!Toggle word wrapToggle overflow
This is how you execute the map of person instances that is produced:
Smooks smooks = new Smooks(configStream);
JavaResult result = new JavaResult();
smooks.filterSource(new StreamSource(fixedLengthStream), result);
Map<String, Person> people = (Map<String, Person>) result.getBean("people");
Person tom = people.get("Tom");
Person mike = people.get("Maurice");
Smooks smooks = new Smooks(configStream);
JavaResult result = new JavaResult();
smooks.filterSource(new StreamSource(fixedLengthStream), result);
Map<String, Person> people = (Map<String, Person>) result.getBean("people");
Person tom = people.get("Tom");
Person mike = people.get("Maurice");
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Virtual Models are also supported, so you can define the class attribute as a java.util.Map and bind the fixed-length field values to map instances, which are in turn added to a list or a map.
We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.
About Red Hat
We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.