org.springframework.integration.adapter.stream
Class CharacterStreamTarget

java.lang.Object
  extended by org.springframework.integration.adapter.stream.CharacterStreamTarget
All Implemented Interfaces:
MessageTarget

public class CharacterStreamTarget
extends java.lang.Object
implements MessageTarget

A target that writes to a Writer. String-based objects will be written directly, but if the object is not itself a String, the target will write the result of the object's Object.toString() method. To append a new-line after each write, set the shouldAppendNewLine flag to true. It is false by default.

Author:
Mark Fisher

Field Summary
private  org.apache.commons.logging.Log logger
           
private  boolean shouldAppendNewLine
           
private  java.io.BufferedWriter writer
           
 
Constructor Summary
CharacterStreamTarget(java.io.Writer writer)
           
CharacterStreamTarget(java.io.Writer writer, int bufferSize)
           
 
Method Summary
private static CharacterStreamTarget createTargetForStream(java.io.OutputStream stream, java.lang.String charsetName)
           
 boolean send(Message message)
          Send a Message to this target.
 void setShouldAppendNewLine(boolean shouldAppendNewLine)
           
static CharacterStreamTarget stderr()
          Factory method that creates a target for stderr (System.err) with the default charset encoding.
static CharacterStreamTarget stderr(java.lang.String charsetName)
          Factory method that creates a target for stderr (System.err) with the specified charset encoding.
static CharacterStreamTarget stdout()
          Factory method that creates a target for stdout (System.out) with the default charset encoding.
static CharacterStreamTarget 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
 

Field Detail

logger

private final org.apache.commons.logging.Log logger

writer

private final java.io.BufferedWriter writer

shouldAppendNewLine

private volatile boolean shouldAppendNewLine
Constructor Detail

CharacterStreamTarget

public CharacterStreamTarget(java.io.Writer writer)

CharacterStreamTarget

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

stdout

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


stdout

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


stderr

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


stderr

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


createTargetForStream

private static CharacterStreamTarget createTargetForStream(java.io.OutputStream stream,
                                                           java.lang.String charsetName)

setShouldAppendNewLine

public void setShouldAppendNewLine(boolean shouldAppendNewLine)

send

public boolean send(Message message)
Description copied from interface: MessageTarget
Send a Message to this target. May throw a RuntimeException for non-recoverable errors. Otherwise, if the Message cannot be sent for a non-fatal reason such as timeout, then this method will return 'false', and if the Message is sent successfully, it will return 'true'.

Specified by:
send in interface MessageTarget
Parameters:
message - the Message to send
Returns:
whether the Message has been sent successfully