Class FileWritingMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Ordered, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, MessageTriggerAction, IntegrationPattern, NamedComponent, IntegrationManagement, ManageableLifecycle, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class FileWritingMessageHandler
extends AbstractReplyProducingMessageHandler
implements ManageableLifecycle, MessageTriggerAction
A MessageHandler implementation that writes the Message payload to a file. If the payload is a File object, it will copy the File to the specified destination directory. If the payload is a byte array, a String or an InputStream it will be written directly. Otherwise, the payload type is unsupported, and an Exception will be thrown.

To append a new-line after each write, set the appendNewLine flag to 'true'. It is 'false' by default.

If the 'deleteSourceFiles' flag is set to true, the original Files will be deleted. The default value for that flag is false. See the setDeleteSourceFiles(boolean) method javadoc for more information.

Other transformers may be useful to precede this handler. For example, any Serializable object payload can be converted into a byte array by the PayloadSerializingTransformer. Likewise, any Object can be converted to a String based on its toString() method by the ObjectToStringTransformer.

FileExistsMode.APPEND adds content to an existing file; the file is closed after each write. FileExistsMode.APPEND_NO_FLUSH adds content to an existing file and the file is left open without flushing any data. Data will be flushed based on the flushInterval or when a message is sent to the trigger(Message) method, or a flushIfNeeded method is called.

Author:
Mark Fisher, Iwein Fuld, Alex Peters, Oleg Zhurakousky, Artem Bilan, Gunnar Hillert, Gary Russell, Tony Falabella, Alen Turkovic, Trung Pham