Search in sources :

Example 1 with SessionCallback

use of org.springframework.integration.file.remote.SessionCallback in project spring-integration-samples by spring-projects.

the class SftpTestUtils method createTestFiles.

public static void createTestFiles(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
    if (template != null) {
        final ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
        template.execute((SessionCallback<LsEntry, Void>) session -> {
            try {
                session.mkdir("si.sftp.sample");
            } catch (Exception e) {
                assertThat(e.getMessage(), containsString("failed to create"));
            }
            for (int i = 0; i < fileNames.length; i++) {
                stream.reset();
                session.write(stream, "si.sftp.sample/" + fileNames[i]);
            }
            return null;
        });
    }
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ByteArrayInputStream(java.io.ByteArrayInputStream) SftpATTRS(com.jcraft.jsch.SftpATTRS) SftpException(com.jcraft.jsch.SftpException) IOException(java.io.IOException) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) RemoteFileTemplate(org.springframework.integration.file.remote.RemoteFileTemplate) SessionCallback(org.springframework.integration.file.remote.SessionCallback) ChannelSftp(com.jcraft.jsch.ChannelSftp) ByteArrayInputStream(java.io.ByteArrayInputStream) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry) SftpException(com.jcraft.jsch.SftpException) IOException(java.io.IOException)

Aggregations

ChannelSftp (com.jcraft.jsch.ChannelSftp)1 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 SftpATTRS (com.jcraft.jsch.SftpATTRS)1 SftpException (com.jcraft.jsch.SftpException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Assert.assertThat (org.junit.Assert.assertThat)1 RemoteFileTemplate (org.springframework.integration.file.remote.RemoteFileTemplate)1 SessionCallback (org.springframework.integration.file.remote.SessionCallback)1