Search in sources :

Example 1 with FileSplitter

use of org.springframework.integration.file.splitter.FileSplitter in project spring-integration by spring-projects.

the class FileSplitterSpec method doGet.

@Override
protected FileSplitter doGet() {
    FileSplitter fileSplitter = new FileSplitter(this.iterator, this.markers, this.markersJson);
    fileSplitter.setApplySequence(this.applySequence);
    fileSplitter.setCharset(this.charset);
    if (StringUtils.hasText(this.firstLineHeaderName)) {
        fileSplitter.setFirstLineAsHeader(this.firstLineHeaderName);
    }
    return fileSplitter;
}
Also used : FileSplitter(org.springframework.integration.file.splitter.FileSplitter)

Example 2 with FileSplitter

use of org.springframework.integration.file.splitter.FileSplitter in project spring-integration by spring-projects.

the class StreamingInboundTests method testLineByLine.

@SuppressWarnings("unchecked")
@Test
public void testLineByLine() throws Exception {
    Streamer streamer = new Streamer(new StringRemoteFileTemplate(new StringSessionFactory()), null);
    streamer.setBeanFactory(mock(BeanFactory.class));
    streamer.setRemoteDirectory("/foo");
    streamer.afterPropertiesSet();
    QueueChannel out = new QueueChannel();
    FileSplitter splitter = new FileSplitter();
    splitter.setBeanFactory(mock(BeanFactory.class));
    splitter.setOutputChannel(out);
    splitter.afterPropertiesSet();
    Message<InputStream> receivedStream = streamer.receive();
    splitter.handleMessage(receivedStream);
    Message<byte[]> received = (Message<byte[]>) out.receive(0);
    assertEquals("foo", received.getPayload());
    assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
    received = (Message<byte[]>) out.receive(0);
    assertEquals("bar", received.getPayload());
    assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
    assertNull(out.receive(0));
    // close by list, splitter
    verify(new IntegrationMessageHeaderAccessor(receivedStream).getCloseableResource(), times(3)).close();
    receivedStream = streamer.receive();
    splitter.handleMessage(receivedStream);
    received = (Message<byte[]>) out.receive(0);
    assertEquals("baz", received.getPayload());
    assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
    received = (Message<byte[]>) out.receive(0);
    assertEquals("qux", received.getPayload());
    assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
    assertNull(out.receive(0));
    // close by splitter
    verify(new IntegrationMessageHeaderAccessor(receivedStream).getCloseableResource(), times(5)).close();
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) FileSplitter(org.springframework.integration.file.splitter.FileSplitter) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Aggregations

FileSplitter (org.springframework.integration.file.splitter.FileSplitter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 Message (org.springframework.messaging.Message)1