Reputation: 251
I am using Spring Integration File Splitter (XML config) to read a file and process the messages.
I have a requirement that I need to read first line and the last line from the file and set them as header value so that rest of the lines/messages have that information.
In other words, first and last line messages need to be discarded but its payload need to be set as header in rest of the messages.
How can I achieve it ? Any help will be appreciated.Thanks.
Following code is there to read the file from directory and split it:
<int-file:inbound-channel-adapter
id="fileSource" channel="fileReceiverChannel"
directory="file:${file.messagesource.directory}"
prevent-duplicates="false" ignore-hidden="true" filename-regex="${filename.regex}" >
<int:poller fixed-delay="5000" receive-timeout="5000"
task-executor="pollerExecutor">
</int:poller>
</int-file:inbound-channel-adapter>
<int-file:splitter id="splitFile"
input-channel="splitFileChannel" output-channel="transformChannel"
charset="UTF-8" apply-sequence="true" iterator="false" />
Upvotes: 0
Views: 707
Reputation: 174604
Since 5.0, you can setFirstLineAsHeader(true)
on the FileSplitter
and the first line will be carried as a header in all messages.
It's first-line-as-header
in the XML configuration.
There is no mechanism to do the same for the "last" line; you would need a custom version of the splitter for that. It's not so easy to read the last line, unless all the lines are the same length you'd have to read the entire file first.
Upvotes: 1