INT-1614 using File instead of Resource for localDirectory
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.Collection;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
@@ -70,7 +69,7 @@ public class SftpInboundFileSynchronizer extends AbstractInboundFileSynchronizer
|
||||
}
|
||||
}
|
||||
|
||||
public void synchronizeToLocalDirectory(Resource localDirectory) {
|
||||
public void synchronizeToLocalDirectory(File localDirectory) {
|
||||
Session session = null;
|
||||
try {
|
||||
session = this.sessionFactory.getSession();
|
||||
@@ -105,9 +104,8 @@ public class SftpInboundFileSynchronizer extends AbstractInboundFileSynchronizer
|
||||
}
|
||||
}
|
||||
|
||||
private boolean copyFromRemoteToLocalDirectory(Session session, ChannelSftp.LsEntry entry, Resource localDir) throws Exception {
|
||||
File fileForLocalDir = localDir.getFile();
|
||||
File localFile = new File(fileForLocalDir, entry.getFilename());
|
||||
private boolean copyFromRemoteToLocalDirectory(Session session, ChannelSftp.LsEntry entry, File localDirectory) throws Exception {
|
||||
File localFile = new File(localDirectory, entry.getFilename());
|
||||
if (!localFile.exists()) {
|
||||
InputStream in = null;
|
||||
FileOutputStream fileOutputStream = null;
|
||||
|
||||
@@ -54,15 +54,15 @@ public class SftpInboundFileSynchronizingMessageSource extends AbstractInboundFi
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create.");
|
||||
}
|
||||
this.localDirectory.getFile().mkdirs();
|
||||
this.localDirectory.mkdirs();
|
||||
}
|
||||
else {
|
||||
throw new FileNotFoundException(this.localDirectory.getFilename());
|
||||
throw new FileNotFoundException(this.localDirectory.getName());
|
||||
}
|
||||
}
|
||||
// Forwards files once they appear in the {@link #localDirectory}.
|
||||
this.fileSource = new FileReadingMessageSource();
|
||||
this.fileSource.setDirectory(this.localDirectory.getFile());
|
||||
this.fileSource.setDirectory(this.localDirectory);
|
||||
this.fileSource.afterPropertiesSet();
|
||||
if (this.filenamePattern != null) {
|
||||
SftpPatternMatchingFileListFilter filter = new SftpPatternMatchingFileListFilter(this.filenamePattern);
|
||||
|
||||
@@ -67,12 +67,12 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
public void testCopyAndRenameWhenLocalFileExists() throws Exception {
|
||||
SftpInboundFileSynchronizer synchronizer = new SftpInboundFileSynchronizer(mock(SessionFactory.class));
|
||||
Method method =
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", Session.class, LsEntry.class, Resource.class);
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", Session.class, LsEntry.class, File.class);
|
||||
method.setAccessible(true);
|
||||
Session session = mock(Session.class);
|
||||
LsEntry entry = mock(LsEntry.class);
|
||||
when(entry.getFilename()).thenReturn("foo.txt");
|
||||
Resource localDir = new FileSystemResource(new File("target"));
|
||||
File localDir = new File("target");
|
||||
boolean success = (Boolean) method.invoke(synchronizer, session, entry, localDir);
|
||||
assertTrue(success);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
@@ -93,7 +91,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
syncronizer.setShouldDeleteSourceFile(true);
|
||||
syncronizer.afterPropertiesSet();
|
||||
|
||||
Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
|
||||
File localDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
syncronizer.synchronizeToLocalDirectory(localDirectory);
|
||||
|
||||
verify(sessionFactory, times(1)).getSession();
|
||||
|
||||
Reference in New Issue
Block a user