Example usage for org.springframework.integration.file.remote RemoteFileTemplate setFileNameExpression

List of usage examples for org.springframework.integration.file.remote RemoteFileTemplate setFileNameExpression

Introduction

In this page you can find the example usage for org.springframework.integration.file.remote RemoteFileTemplate setFileNameExpression.

Prototype

public void setFileNameExpression(Expression fileNameExpression) 

Source Link

Document

Set the file name expression to determine the full path to the remote file when retrieving a file using the #get(Message,InputStreamCallback) method, with the message being the root object of the evaluation.

Usage

From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java

@Test
public void testRawGETWithTemplate() throws Exception {
    RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<FTPFile>(this.ftpSessionFactory);
    template.setFileNameExpression(new SpelExpressionParser().parseExpression("payload"));
    template.setBeanFactory(mock(BeanFactory.class));
    template.afterPropertiesSet();/*  w  w  w. j  av  a 2s.  com*/
    final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
    assertTrue(template.get(new GenericMessage<String>("ftpSource/ ftpSource1.txt"),
            (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos1)));
    assertEquals("source1", new String(baos1.toByteArray()));

    final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    assertTrue(template.get(new GenericMessage<String>("ftpSource/ftpSource2.txt"),
            (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos2)));
    assertEquals("source2", new String(baos2.toByteArray()));
}