16.4 File Transformers

To transform data read from the file system to objects and the other way around you need to do some work. Contrary to FileReadingMessageSource and to a lesser extent FileWritingMessageHandler it is very likely that you will need your own mechanism to get the job done. For this you can implement the Transformer interface. Or extend the AbstractFilePayloadTransformer for inbound messages. Some obvious implementations have been provided.

FileToByteArrayTransformer transforms Files into byte[]s using FileCopyUtils . It is often better to use a sequence of transformers than to put all transformations in a single class, in that case the File to byte[] conversion might be a logical first step.

FileToStringTransformer will convert Files to Strings as the name suggests. This is mainly useful for debugging.

To configure File specific transformers you can use the appropriate elements from the file namespace.

<file-to-bytes-transformer input-channel="input" output-channel="output" delete-files="true"/>

The delete-files option signals the transformer to delete the File after the transformation is done. This is in no way a replacement for using the AcceptOnceFileListFilter with the PollableFileSource in a multi-threaded environment (e.g. Spring Integration in general).