diff --git a/spring-integration-reference/src/file.xml b/spring-integration-reference/src/file.xml index 43504bbb83..ebf39cad55 100644 --- a/spring-integration-reference/src/file.xml +++ b/spring-integration-reference/src/file.xml @@ -97,29 +97,101 @@ ]]> Within this namespace you can reduce the PollableFileSource and wrap it in a InboundChannelAdapter like this: - - (1) (2) (3) ]]> + Where (1) is relying on the default filter that just prevents + duplication, (2) is using a custom filter and (3) is using the + filename-pattern + attribute to add a + Pattern + based filter to the + PollableFileSource
Writing files - + To write messages to the file system you can use a + FileWritingMessageConsumer + + . This class can deal with File or byte[] payloads and otherwise + invokes the toString() method on the payload to estabish the contents + of the File. In its simplest form the + FileWritingMessageConsumer + + just needs a parent directory for the files. - + Additionally, you can + configure the encoding and the charset that + will + be used in case of a + fallback on the toString() method. - + To make things easier you can configure the + FileWritingMessageConsumer as part of an outbound channel adapter + using the namespace. + + ]]> + + + If you have more elaborate requirements to the payload to file + conversion you could extend the FileWritingMessageConsumer, but a + much better option is to rely on a + Transformer + +
+
+ + + To transform data read from the file system to objects and the other + way around you need to do some work. Contrary to + PollableFileSource + and to a lesser extent + FileWritingMessageConsumer + + 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. + + + To configure File specific transformers you can use the appropriate + elements from the file namespace. + ]]> + 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).
\ No newline at end of file