Hi Jim,
This may be a bit of a hack, but it could work (I didn't test it
myself), or at least get you on the right track... A BeanIO delimited
stream format writes records using a String array, so the position of
a field in the mapping file will always dictate the position of the
field in the array object passed to the writer. So with that in mind,
you can probably override the default writer with something like the
following:
public class TagDelimitedWriter implements RecordWriter {
private static final char delim = ',';
private static final String [] field = {
"FIRSTNAME",
"LASTNAME",
"ADDRESS1",
"ADDRESS2"
};
private Writer out;
public TagDelimitedWriter(Writer out) {
this.out = out;
}
public void write(Object recordObject) throws IOException {
int fieldCount = 0;
String [] value = (String[]) recordObject;
for (int i=0,j=field.length; i<j; i++) {
if (!"".equals(value[i])) {
if (++fieldCount > 1) {
out.write(delim);
}
out.write(field[i]);
out.write("(");
out.write(value[i]);
out.write(")");
}
}
out.write("\n");
}
public void flush() throws IOException {
out.flush();
}
public void close() throws IOException {
out.close();
}
}
You'll then need to create a RecordWriterFactory for this like so:
public class TagDelimitedWriterFactory implements RecordWriterFactory
{
public RecordWriter createWriter(Writer out) throws
IllegalArgumentException {
return new TagDelimitedWriter(out);
}
}
And register its use in your mapping file:
<stream name="..." format="delimited">
<writer class="example.TagDelimitedWriterFactory" />
...
</stream>
If you need to support multiple record types, the solution will get a
bit trickier, but you could add a field in the first position of the
record that identifies the record type using a literal value (with
ignore="true"), and use the literal value to determine the field list
in your writer...
Thanks,
Kevin