public class CharacterStreamReadingMessageSource extends IntegrationObjectSupport implements MessageSource<java.lang.String>, org.springframework.context.ApplicationEventPublisherAware
Readers
.EXPRESSION_PARSER, logger
Constructor and Description |
---|
CharacterStreamReadingMessageSource(java.io.Reader reader)
Construct an instance with the provider reader.
|
CharacterStreamReadingMessageSource(java.io.Reader reader,
int bufferSize)
Construct an instance with the provider reader and buffer size.
|
CharacterStreamReadingMessageSource(java.io.Reader reader,
int bufferSize,
boolean blockToDetectEOF)
Construct an instance with the provided reader and buffer size.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
org.springframework.messaging.Message<java.lang.String> |
receive()
Retrieve the next available message from this source.
|
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
static CharacterStreamReadingMessageSource |
stdin()
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdin(java.lang.String charsetName)
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdinPipe()
Create a source that reads from
System.in . |
static CharacterStreamReadingMessageSource |
stdinPipe(java.lang.String charsetName)
Create a source that reads from
System.in . |
afterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
public CharacterStreamReadingMessageSource(java.io.Reader reader)
receive()
will return null
when the reader is not ready.reader
- the reader.public CharacterStreamReadingMessageSource(java.io.Reader reader, int bufferSize)
receive()
will return null
when the reader is not ready.reader
- the reader.bufferSize
- the buffer size.public CharacterStreamReadingMessageSource(java.io.Reader reader, int bufferSize, boolean blockToDetectEOF)
blockToDetectEOF
is false
,
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(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
public java.lang.String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class IntegrationObjectSupport
public org.springframework.messaging.Message<java.lang.String> receive()
MessageSource
null
if no message is available.receive
in interface MessageSource<java.lang.String>
public static final CharacterStreamReadingMessageSource stdin()
System.in
. EOF will not be detected.public static final CharacterStreamReadingMessageSource stdin(java.lang.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(java.lang.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)