Refactored stream targets to outboundChannelAdapters.

This commit is contained in:
Mark Fisher
2008-09-18 12:40:38 +00:00
parent d8ebbe5994
commit fe14643a8d
13 changed files with 94 additions and 94 deletions

View File

@@ -28,22 +28,22 @@ import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessagingException;
/**
* A target that writes a byte array to an {@link OutputStream}.
* An outbound Channel Adapter that writes a byte array to an {@link OutputStream}.
*
* @author Mark Fisher
*/
public class ByteStreamTarget extends AbstractMessageConsumingEndpoint {
public class ByteStreamOutboundChannelAdapter extends AbstractMessageConsumingEndpoint {
private final Log logger = LogFactory.getLog(this.getClass());
private final BufferedOutputStream stream;
public ByteStreamTarget(OutputStream stream) {
public ByteStreamOutboundChannelAdapter(OutputStream stream) {
this(stream, -1);
}
public ByteStreamTarget(OutputStream stream, int bufferSize) {
public ByteStreamOutboundChannelAdapter(OutputStream stream, int bufferSize) {
if (bufferSize > 0) {
this.stream = new BufferedOutputStream(stream, bufferSize);
}

View File

@@ -33,15 +33,15 @@ import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
/**
* A target that writes to a {@link Writer}. String-based objects will be
* written directly, but if the object is not itself a {@link String}, the
* target will write the result of the object's {@link #toString()} method.
* To append a new-line after each write, set the {@link #shouldAppendNewLine}
* flag to <em>true</em>. It is <em>false</em> by default.
* An outbound Channel Adapter that writes to a {@link Writer}. String-based objects
* will be written directly, but if the object is not itself a {@link String}, the
* target will write the result of the object's {@link #toString()} method. To
* append a new-line after each write, set the {@link #shouldAppendNewLine} flag to
* <em>true</em>. It is <em>false</em> by default.
*
* @author Mark Fisher
*/
public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
public class CharacterStreamOutboundChannelAdapter extends AbstractMessageConsumingEndpoint {
private final Log logger = LogFactory.getLog(this.getClass());
@@ -50,11 +50,11 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
private volatile boolean shouldAppendNewLine = false;
public CharacterStreamTarget(Writer writer) {
public CharacterStreamOutboundChannelAdapter(Writer writer) {
this(writer, -1);
}
public CharacterStreamTarget(Writer writer, int bufferSize) {
public CharacterStreamOutboundChannelAdapter(Writer writer, int bufferSize) {
Assert.notNull(writer, "writer must not be null");
if (writer instanceof BufferedWriter) {
this.writer = (BufferedWriter) writer;
@@ -72,7 +72,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
* Factory method that creates a target for stdout (System.out) with the
* default charset encoding.
*/
public static CharacterStreamTarget stdout() {
public static CharacterStreamOutboundChannelAdapter stdout() {
return stdout(null);
}
@@ -80,7 +80,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
* Factory method that creates a target for stdout (System.out) with the
* specified charset encoding.
*/
public static CharacterStreamTarget stdout(String charsetName) {
public static CharacterStreamOutboundChannelAdapter stdout(String charsetName) {
return createTargetForStream(System.out, charsetName);
}
@@ -88,7 +88,7 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
* Factory method that creates a target for stderr (System.err) with the
* default charset encoding.
*/
public static CharacterStreamTarget stderr() {
public static CharacterStreamOutboundChannelAdapter stderr() {
return stderr(null);
}
@@ -96,16 +96,16 @@ public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
* Factory method that creates a target for stderr (System.err) with the
* specified charset encoding.
*/
public static CharacterStreamTarget stderr(String charsetName) {
public static CharacterStreamOutboundChannelAdapter stderr(String charsetName) {
return createTargetForStream(System.err, charsetName);
}
private static CharacterStreamTarget createTargetForStream(OutputStream stream, String charsetName) {
private static CharacterStreamOutboundChannelAdapter createTargetForStream(OutputStream stream, String charsetName) {
if (charsetName == null) {
return new CharacterStreamTarget(new OutputStreamWriter(stream));
return new CharacterStreamOutboundChannelAdapter(new OutputStreamWriter(stream));
}
try {
return new CharacterStreamTarget(new OutputStreamWriter(stream, charsetName));
return new CharacterStreamOutboundChannelAdapter(new OutputStreamWriter(stream, charsetName));
}
catch (UnsupportedEncodingException e) {
throw new ConfigurationException("unsupported encoding: " + charsetName, e);

View File

@@ -30,7 +30,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class ConsoleSourceParser extends AbstractPollingInboundChannelAdapterParser {
public class ConsoleInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
@Override
protected String parseSource(Element element, ParserContext parserContext) {

View File

@@ -27,7 +27,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.stream.CharacterStreamTarget;
import org.springframework.integration.stream.CharacterStreamOutboundChannelAdapter;
import org.springframework.util.StringUtils;
/**
@@ -35,11 +35,11 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
public class ConsoleOutboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return CharacterStreamTarget.class;
return CharacterStreamOutboundChannelAdapter.class;
}
@Override

View File

@@ -24,9 +24,9 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
public class StreamNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
this.registerBeanDefinitionParser("stdin-channel-adapter", new ConsoleSourceParser());
this.registerBeanDefinitionParser("stdout-channel-adapter", new ConsoleTargetParser());
this.registerBeanDefinitionParser("stderr-channel-adapter", new ConsoleTargetParser());
this.registerBeanDefinitionParser("stdin-channel-adapter", new ConsoleInboundChannelAdapterParser());
this.registerBeanDefinitionParser("stdout-channel-adapter", new ConsoleOutboundChannelAdapterParser());
this.registerBeanDefinitionParser("stderr-channel-adapter", new ConsoleOutboundChannelAdapterParser());
}
}