diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java index a78bea992f..cd65c0a7bf 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java @@ -16,12 +16,14 @@ package org.springframework.integration.file.synchronization; +import java.util.Arrays; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; -import org.springframework.integration.file.filters.AcceptAllFileListFilter; import org.springframework.integration.file.filters.FileListFilter; /** @@ -48,23 +50,27 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer implements I /** * The directory to which we write our synchronizations. */ - protected volatile Resource localDirectory; + private volatile Resource localDirectory; /** * An {@link FileListFilter} that runs against the remote file system view. */ - protected volatile FileListFilter filter = new AcceptAllFileListFilter(); + private volatile FileListFilter filter; /** * The {@link EntryAcknowledgmentStrategy} implementation. */ - protected EntryAcknowledgmentStrategy entryAcknowledgmentStrategy; + private EntryAcknowledgmentStrategy entryAcknowledgmentStrategy; public void setLocalDirectory(Resource localDirectory) { this.localDirectory = localDirectory; } + protected Resource getLocalDirectory() { + return this.localDirectory; + } + public void setFilter(FileListFilter filter) { this.filter = filter; } @@ -91,12 +97,16 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer implements I * @throws Exception * escape hatch exception, let the adapter deal with it. */ - protected void acknowledge(Object usefulContextOrClientData, F file) throws Exception { + protected final void acknowledge(Object usefulContextOrClientData, F file) throws Exception { if (this.entryAcknowledgmentStrategy != null) { this.entryAcknowledgmentStrategy.acknowledge(usefulContextOrClientData, file); } } + protected final List filterFiles(F[] files) { + return (this.filter != null) ? this.filter.filterFiles(files) : Arrays.asList(files); + } + /** * This is the callback where the subclasses must synchronize. */ diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java index 3ddc018f75..6cf1eab8ec 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java @@ -57,7 +57,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot public void afterPropertiesSet() throws Exception { Assert.notNull(this.clientPool, "clientPool must not be null"); if (this.shouldDeleteSourceFile) { - this.entryAcknowledgmentStrategy = new DeletionEntryAcknowledgmentStrategy(); + this.setEntryAcknowledgmentStrategy(new DeletionEntryAcknowledgmentStrategy()); } } @@ -69,11 +69,11 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot FtpClientPool.class.getSimpleName() + " returned a 'null' client. " + "This is most likely a bug in the pool implementation."); - Collection fileList = this.filter.filterFiles(client.listFiles()); + Collection fileList = this.filterFiles(client.listFiles()); try { for (FTPFile ftpFile : fileList) { if ((ftpFile != null) && ftpFile.isFile()) { - copyFileToLocalDirectory(client, ftpFile, this.localDirectory); + copyFileToLocalDirectory(client, ftpFile, this.getLocalDirectory()); } } } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java index 63eb36730a..216ef3196e 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java @@ -73,7 +73,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych public void afterPropertiesSet() throws Exception { Assert.notNull(this.remotePath, "'remotePath' must not be null"); if (this.shouldDeleteSourceFile) { - this.entryAcknowledgmentStrategy = new DeletionEntryAcknowledgmentStrategy(); + this.setEntryAcknowledgmentStrategy(new DeletionEntryAcknowledgmentStrategy()); } } @@ -129,10 +129,10 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych Collection beforeFilter = channelSftp.ls(remotePath); ChannelSftp.LsEntry[] entries = (beforeFilter == null) ? new ChannelSftp.LsEntry[0] : beforeFilter.toArray(new ChannelSftp.LsEntry[beforeFilter.size()]); - Collection files = this.filter.filterFiles(entries); + Collection files = this.filterFiles(entries); for (ChannelSftp.LsEntry lsEntry : files) { if ((lsEntry != null) && !lsEntry.getAttrs().isDir() && !lsEntry.getAttrs().isLink()) { - copyFromRemoteToLocalDirectory(session, lsEntry, this.localDirectory); + copyFromRemoteToLocalDirectory(session, lsEntry, this.getLocalDirectory()); } } } @@ -164,7 +164,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych IOUtils.closeQuietly(in); IOUtils.closeQuietly(fileOutputStream); } - if (tmpLocalTarget.renameTo(localFile) && this.entryAcknowledgmentStrategy != null) { + if (tmpLocalTarget.renameTo(localFile)) { this.acknowledge(sftpSession, entry); } return true;