/** * Create a source that reads from {@link System#in}. EOF will not be detected. * @return the stream. */ public static final CharacterStreamReadingMessageSource stdin() { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in)); }
/** * Create a source that reads from {@link System#in}. EOF will be detected and the application * context closed. * @return the stream. * @see CharacterStreamReadingMessageSource#CharacterStreamReadingMessageSource(Reader, int, boolean) * @since 5.0 */ public static final CharacterStreamReadingMessageSource stdinPipe() { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in), -1, true); }
/** * Create a source that reads from {@link System#in}. EOF will not be detected. * @param charsetName the charset to use when converting bytes to String. * @return the stream. */ public static final CharacterStreamReadingMessageSource stdin(String charsetName) { try { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in, charsetName)); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("unsupported encoding: " + charsetName, e); } }
/** * Create a source that reads from {@link System#in}. EOF will be detected and the application * context closed. * @param charsetName the charset to use when converting bytes to String. * @return the stream. * @see CharacterStreamReadingMessageSource#CharacterStreamReadingMessageSource(Reader, int, boolean) * @since 5.0 */ public static final CharacterStreamReadingMessageSource stdinPipe(String charsetName) { try { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in, charsetName), -1, true); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("unsupported encoding: " + charsetName, e); } }
@Test public void testEOF() { StringReader reader = new StringReader("test"); CharacterStreamReadingMessageSource source = new CharacterStreamReadingMessageSource(reader, -1, true); ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class); source.setApplicationEventPublisher(publisher); Message<?> message1 = source.receive(); assertEquals("test", message1.getPayload()); Message<?> message2 = source.receive(); assertNull(message2); verify(publisher).publishEvent(any(StreamClosedEvent.class)); }
@Test public void testEndOfStream() { StringReader reader = new StringReader("test"); CharacterStreamReadingMessageSource source = new CharacterStreamReadingMessageSource(reader); Message<?> message1 = source.receive(); assertEquals("test", message1.getPayload()); Message<?> message2 = source.receive(); assertNull(message2); }
/** * Create a source that reads from {@link System#in}. EOF will not be detected. * @return the stream. */ public static final CharacterStreamReadingMessageSource stdin() { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in)); }
/** * Create a source that reads from {@link System#in}. EOF will be detected and the application * context closed. * @return the stream. * @see CharacterStreamReadingMessageSource#CharacterStreamReadingMessageSource(Reader, int, boolean) * @since 5.0 */ public static final CharacterStreamReadingMessageSource stdinPipe() { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in), -1, true); }
/** * Create a source that reads from {@link System#in}. EOF will not be detected. * @param charsetName the charset to use when converting bytes to String. * @return the stream. */ public static final CharacterStreamReadingMessageSource stdin(String charsetName) { try { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in, charsetName)); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("unsupported encoding: " + charsetName, e); } }
@Test public void testEOFIntegrationTest() throws Exception { StringReader reader = new StringReader("test"); CharacterStreamReadingMessageSource source = new CharacterStreamReadingMessageSource(reader, -1, true); SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); CountDownLatch latch = new CountDownLatch(2);
/** * Create a source that reads from {@link System#in}. EOF will be detected and the application * context closed. * @param charsetName the charset to use when converting bytes to String. * @return the stream. * @see CharacterStreamReadingMessageSource#CharacterStreamReadingMessageSource(Reader, int, boolean) * @since 5.0 */ public static final CharacterStreamReadingMessageSource stdinPipe(String charsetName) { try { return new CharacterStreamReadingMessageSource(new InputStreamReader(System.in, charsetName), -1, true); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("unsupported encoding: " + charsetName, e); } }