org.springframework.integration.file
Class FileWritingMessageHandler

java.lang.Object
  extended by org.springframework.integration.handler.AbstractMessageHandler
      extended by org.springframework.integration.handler.AbstractReplyProducingMessageHandler
          extended by org.springframework.integration.file.FileWritingMessageHandler
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered, MessageHandler

public class FileWritingMessageHandler
extends AbstractReplyProducingMessageHandler
implements org.springframework.beans.factory.InitializingBean

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 or String, it will write it directly. Otherwise, the payload type is unsupported, and an Exception will be thrown.

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.

Author:
Mark Fisher, Iwein Fuld, Alex Peters

Field Summary
 
Fields inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
DEFAULT_SEND_TIMEOUT
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
FileWritingMessageHandler(org.springframework.core.io.Resource destinationDirectory)
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void handleRequestMessage(Message<?> requestMessage, ReplyMessageHolder replyMessageHolder)
           
 void setAutoCreateDirectory(boolean autoCreateDirectory)
          Specify whether to create the destination directory automatically if it does not yet exist upon initialization.
 void setCharset(java.lang.String charset)
          Set the charset name to use when writing a File from a String-based Message payload.
 void setDeleteSourceFiles(boolean deleteSourceFiles)
          Specify whether to delete source Files after writing to the destination directory.
 void setFileNameGenerator(FileNameGenerator fileNameGenerator)
          Provide the FileNameGenerator strategy to use when generating the destination file's name.
 
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getOutputChannel, handleMessageInternal, sendReplyMessage, setBeanFactory, setChannelResolver, setOutputChannel, setRequiresReply, setSendTimeout
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getOrder, handleMessage, setOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileWritingMessageHandler

public FileWritingMessageHandler(org.springframework.core.io.Resource destinationDirectory)
Method Detail

setAutoCreateDirectory

public void setAutoCreateDirectory(boolean autoCreateDirectory)
Specify whether to create the destination directory automatically if it does not yet exist upon initialization. By default, this value is true. If set to false and the destination directory does not exist, an Exception will be thrown upon initialization.


setFileNameGenerator

public void setFileNameGenerator(FileNameGenerator fileNameGenerator)
Provide the FileNameGenerator strategy to use when generating the destination file's name.


setDeleteSourceFiles

public void setDeleteSourceFiles(boolean deleteSourceFiles)
Specify whether to delete source Files after writing to the destination directory. The default is false. When set to true, it will only have an effect if the inbound Message has a File payload or a FileHeaders.ORIGINAL_FILE header value containing either a File instance or a String representing the original file path.


setCharset

public void setCharset(java.lang.String charset)
Set the charset name to use when writing a File from a String-based Message payload.


afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

handleRequestMessage

protected void handleRequestMessage(Message<?> requestMessage,
                                    ReplyMessageHolder replyMessageHolder)
Specified by:
handleRequestMessage in class AbstractReplyProducingMessageHandler