Example usage for org.springframework.integration.ftp.session FtpRemoteFileTemplate executeWithClient

List of usage examples for org.springframework.integration.ftp.session FtpRemoteFileTemplate executeWithClient

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.session FtpRemoteFileTemplate executeWithClient.

Prototype

@SuppressWarnings("unchecked")
    @Override
    public <T, C> T executeWithClient(final ClientCallback<C, T> callback) 

Source Link

Usage

From source file:org.springframework.integration.ftp.session.FtpRemoteFileTemplateTests.java

@Test
public void testINT3412AppendStatRmdir() throws IOException {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
    DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
    fileNameGenerator.setExpression("'foobar.txt'");
    template.setFileNameGenerator(fileNameGenerator);
    template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
    template.setUseTemporaryFileName(false);
    template.execute(session -> {/*  w w w . j a v  a2 s. com*/
        session.mkdir("foo/");
        return session.mkdir("foo/bar/");
    });
    template.append(new GenericMessage<String>("foo"));
    template.append(new GenericMessage<String>("bar"));
    assertTrue(template.exists("foo/foobar.txt"));
    template.executeWithClient((ClientCallbackWithoutResult<FTPClient>) client -> {
        try {
            FTPFile[] files = client.listFiles("foo/foobar.txt");
            assertEquals(6, files[0].getSize());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    template.execute((SessionCallbackWithoutResult<FTPFile>) session -> {
        assertTrue(session.remove("foo/foobar.txt"));
        assertTrue(session.rmdir("foo/bar/"));
        FTPFile[] files = session.list("foo/");
        assertEquals(0, files.length);
        assertTrue(session.rmdir("foo/"));
    });
    assertFalse(template.getSession().exists("foo"));
}