Fix new Sonar issues
This commit is contained in:
@@ -28,6 +28,7 @@ import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.IgnoreHiddenFileListFilter;
|
||||
import org.springframework.integration.file.filters.RegexPatternFileListFilter;
|
||||
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -91,6 +92,7 @@ public class FileListFilterFactoryBean implements FactoryBean<FileListFilter<Fil
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public FileListFilter<File> getObject() {
|
||||
if (this.result == null) {
|
||||
synchronized (this.monitor) {
|
||||
|
||||
@@ -116,7 +116,9 @@ public class CompositeFileListFilter<F>
|
||||
}
|
||||
}
|
||||
this.fileFilters.addAll(filtersToAdd);
|
||||
this.allSupportAccept &= filtersToAdd.stream().allMatch(FileListFilter<F>::supportsSingleFileFiltering);
|
||||
if (this.allSupportAccept) {
|
||||
this.allSupportAccept = filtersToAdd.stream().allMatch(FileListFilter<F>::supportsSingleFileFiltering);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
|
||||
for (F file : filteredFiles) {
|
||||
if (filteringOneByOne) {
|
||||
if ((maxFetchSize < 0 || accepted < maxFetchSize) && this.filter.accept(file)) {
|
||||
if ((maxFetchSize < 0 || accepted < maxFetchSize) && this.filter.accept(file)) { // NOSONAR never null
|
||||
accepted++;
|
||||
}
|
||||
else {
|
||||
@@ -342,21 +342,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file,
|
||||
localDirectory, session)) {
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e1) {
|
||||
if (filteringOneByOne) {
|
||||
resetFilterIfNecessary(file);
|
||||
}
|
||||
else {
|
||||
rollbackFromFileToListEnd(filteredFiles, file);
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
copied = copyIfNotNull(localDirectory, session, filteringOneByOne, filteredFiles, copied, file);
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
@@ -365,6 +351,27 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
}
|
||||
}
|
||||
|
||||
private int copyIfNotNull(File localDirectory, Session<F> session, boolean filteringOneByOne, List<F> filteredFiles,
|
||||
int copied, F file) throws IOException {
|
||||
|
||||
try {
|
||||
if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file,
|
||||
localDirectory, session)) {
|
||||
copied--;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e1) {
|
||||
if (filteringOneByOne) {
|
||||
resetFilterIfNecessary(file);
|
||||
}
|
||||
else {
|
||||
rollbackFromFileToListEnd(filteredFiles, file);
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
private List<F> applyFilter(F[] files, boolean haveFilter, boolean filteringOneByOne, int maxFetchSize) {
|
||||
List<F> filteredFiles;
|
||||
if (!filteringOneByOne && haveFilter) {
|
||||
@@ -373,15 +380,13 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
else {
|
||||
filteredFiles = Arrays.asList(files);
|
||||
}
|
||||
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize) {
|
||||
if (!filteringOneByOne) {
|
||||
if (haveFilter) {
|
||||
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
|
||||
}
|
||||
filteredFiles = filteredFiles.stream()
|
||||
.limit(maxFetchSize)
|
||||
.collect(Collectors.toList());
|
||||
if (maxFetchSize >= 0 && filteredFiles.size() > maxFetchSize && !filteringOneByOne) {
|
||||
if (haveFilter) {
|
||||
rollbackFromFileToListEnd(filteredFiles, filteredFiles.get(maxFetchSize));
|
||||
}
|
||||
filteredFiles = filteredFiles.stream()
|
||||
.limit(maxFetchSize)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return filteredFiles;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user