public class CharacterStreamReadingMessageSource extends AbstractMessageSource<String> implements ApplicationEventPublisherAware
Readers
.IntegrationManagement.ManagementOverrides
EXPRESSION_PARSER, logger
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Constructor and Description |
---|
CharacterStreamReadingMessageSource(Reader reader)
Construct an instance with the provider reader.
|
CharacterStreamReadingMessageSource(Reader reader,
int bufferSize)
Construct an instance with the provider reader and buffer size.
|
CharacterStreamReadingMessageSource(Reader reader,
int bufferSize,
boolean blockToDetectEOF)
Construct an instance with the provided reader and buffer size.
|
Modifier and Type | Method and Description |
---|---|
String |
doReceive()
Subclasses must implement this method.
|
String |
getComponentType() |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
static CharacterStreamReadingMessageSource |
stdin()
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdin(String charsetName)
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdinPipe()
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdinPipe(String charsetName)
Create a source that reads from
System.in . |
buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedType
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, onInit, setBeanFactory, setConversionService
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getIntegrationPatternType
getThisAs
public CharacterStreamReadingMessageSource(Reader reader)
AbstractMessageSource.receive()
will return null
when the reader is not ready.reader
- the reader.public CharacterStreamReadingMessageSource(Reader reader, int bufferSize)
AbstractMessageSource.receive()
will return null
when the reader is not ready.reader
- the reader.bufferSize
- the buffer size.public CharacterStreamReadingMessageSource(Reader reader, int bufferSize, boolean blockToDetectEOF)
blockToDetectEOF
is false
,
AbstractMessageSource.receive()
will return null
when the reader is not ready.
When it is true
, the thread will block until data is available; when the
underlying stream is closed, a StreamClosedEvent
is published to inform
the application via an ApplicationListener
.
This can be useful, for example, when piping stdin
cat foo.txt | java -jar my.jaror
java -jar my.jar < foo.txt
reader
- the reader.bufferSize
- the buffer size; if negative use the default in
BufferedReader
.blockToDetectEOF
- true to block the thread until data is available and
publish a StreamClosedEvent
at EOF.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public String getComponentType()
getComponentType
in interface NamedComponent
public String doReceive()
AbstractMessageSource
payload
of
type T, but the returned value may also be a Message
instance whose payload is of type T;
also can be AbstractIntegrationMessageBuilder
which is used for additional headers population.doReceive
in class AbstractMessageSource<String>
public static final CharacterStreamReadingMessageSource stdin()
System.in
. EOF will not be detected.public static final CharacterStreamReadingMessageSource stdin(String charsetName)
System.in
. EOF will not be detected.charsetName
- the charset to use when converting bytes to String.public static final CharacterStreamReadingMessageSource stdinPipe()
System.in
. EOF will be detected and the application
context closed.CharacterStreamReadingMessageSource(Reader, int, boolean)
public static final CharacterStreamReadingMessageSource stdinPipe(String charsetName)
System.in
. EOF will be detected and the application
context closed.charsetName
- the charset to use when converting bytes to String.CharacterStreamReadingMessageSource(Reader, int, boolean)