org.springframework.integration.stream
Class CharacterStreamWritingMessageHandler

java.lang.Object
  extended by org.springframework.integration.stream.CharacterStreamWritingMessageHandler
All Implemented Interfaces:
MessageHandler

public class CharacterStreamWritingMessageHandler
extends java.lang.Object
implements MessageHandler

A MessageHandler that writes characters to a Writer. String, character array, and byte array payloads will be written directly, but for other payload types, the result of the object's Object.toString() method will be written. To append a new-line after each write, set the shouldAppendNewLine flag to 'true'. It is 'false' by default.

Author:
Mark Fisher

Constructor Summary
CharacterStreamWritingMessageHandler(java.io.Writer writer)
           
CharacterStreamWritingMessageHandler(java.io.Writer writer, int bufferSize)
           
 
Method Summary
 void handleMessage(Message<?> message)
          Handles the message if possible.
 void setShouldAppendNewLine(boolean shouldAppendNewLine)
           
static CharacterStreamWritingMessageHandler stderr()
          Factory method that creates a target for stderr (System.err) with the default charset encoding.
static CharacterStreamWritingMessageHandler stderr(java.lang.String charsetName)
          Factory method that creates a target for stderr (System.err) with the specified charset encoding.
static CharacterStreamWritingMessageHandler stdout()
          Factory method that creates a target for stdout (System.out) with the default charset encoding.
static CharacterStreamWritingMessageHandler stdout(java.lang.String charsetName)
          Factory method that creates a target for stdout (System.out) with the specified charset encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharacterStreamWritingMessageHandler

public CharacterStreamWritingMessageHandler(java.io.Writer writer)

CharacterStreamWritingMessageHandler

public CharacterStreamWritingMessageHandler(java.io.Writer writer,
                                            int bufferSize)
Method Detail

stdout

public static CharacterStreamWritingMessageHandler stdout()
Factory method that creates a target for stdout (System.out) with the default charset encoding.


stdout

public static CharacterStreamWritingMessageHandler stdout(java.lang.String charsetName)
Factory method that creates a target for stdout (System.out) with the specified charset encoding.


stderr

public static CharacterStreamWritingMessageHandler stderr()
Factory method that creates a target for stderr (System.err) with the default charset encoding.


stderr

public static CharacterStreamWritingMessageHandler stderr(java.lang.String charsetName)
Factory method that creates a target for stderr (System.err) with the specified charset encoding.


setShouldAppendNewLine

public void setShouldAppendNewLine(boolean shouldAppendNewLine)

handleMessage

public void handleMessage(Message<?> message)
Description copied from interface: MessageHandler
Handles the message if possible. If the handler cannot deal with the message this will result in a MessageRejectedException e.g. in case of a Selective Consumer. When a consumer tries to handle a message, but fails to do so, a MessageHandlingException is thrown. In the last case it is recommended to treat the message as tainted and go into an error scenario.

When the handling results in a message being sent failure to send that message will result in a MessageDeliveryException.

Specified by:
handleMessage in interface MessageHandler
Parameters:
message - the message to be handled