INT-1591 removed 'entries' package
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A convenience base class for any {@link EntryListFilter} whose criteria can be
|
||||
* evaluated against each File in isolation. If the entire List of files is
|
||||
* required for evaluation, implement the {@link EntryListFilter} interface directly.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
*/
|
||||
public abstract class AbstractEntryListFilter<T> implements InitializingBean, EntryListFilter<T> {
|
||||
|
||||
/**
|
||||
* subclasses may override this if initialization is required
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List<T> filterEntries(T[] entries) {
|
||||
List<T> accepted = new ArrayList<T>();
|
||||
if (entries != null) {
|
||||
for (T t : entries) {
|
||||
if (this.accept(t)) {
|
||||
accepted.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* subclasses must implement this method
|
||||
*/
|
||||
public abstract boolean accept(T entry);
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
/**
|
||||
* Simple NO-OP implementation of {@link org.springframework.integration.file.entries.EntryListFilter}.
|
||||
* Suitable as a default.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
* @param <T>
|
||||
*/
|
||||
public class AcceptAllEntryListFilter<T> extends AbstractEntryListFilter<T> {
|
||||
|
||||
@Override
|
||||
public boolean accept(T entry) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* {@link EntryListFilter} that passes files only one time. This can
|
||||
* conveniently be used to prevent duplication of files, as is done in
|
||||
* {@link org.springframework.integration.file.FileReadingMessageSource}.
|
||||
* <p/>
|
||||
* This implementation is thread safe.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AcceptOnceEntryFileListFilter<T> extends AbstractEntryListFilter<T> {
|
||||
|
||||
private final Queue<T> seen;
|
||||
|
||||
private final Object monitor = new Object();
|
||||
|
||||
|
||||
/**
|
||||
* Creates an {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter}
|
||||
* that is based on a bounded queue. If the queue overflows, files that fall out will be passed
|
||||
* through this filter again if passed to the {@link #filterEntries(Object[])} method.
|
||||
*
|
||||
* @param maxCapacity the maximum number of Files to maintain in the 'seen' queue.
|
||||
*/
|
||||
public AcceptOnceEntryFileListFilter(int maxCapacity) {
|
||||
this.seen = new LinkedBlockingQueue<T>(maxCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AcceptOnceFileFilter based on an unbounded queue.
|
||||
*/
|
||||
public AcceptOnceEntryFileListFilter() {
|
||||
this.seen = new LinkedBlockingQueue<T>();
|
||||
}
|
||||
|
||||
|
||||
public boolean accept(T pathname) {
|
||||
synchronized (this.monitor) {
|
||||
if (this.seen.contains(pathname)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.seen.offer(pathname)) {
|
||||
this.seen.poll();
|
||||
this.seen.add(pathname);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Simple {@link org.springframework.integration.file.entries.EntryListFilter} that predicates its matches
|
||||
* against any of many configured {@link org.springframework.integration.file.entries.EntryListFilter}
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class CompositeEntryListFilter<T> implements EntryListFilter<T> {
|
||||
|
||||
private final Set<EntryListFilter<T>> fileFilters;
|
||||
|
||||
|
||||
public CompositeEntryListFilter() {
|
||||
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>();
|
||||
}
|
||||
|
||||
public CompositeEntryListFilter(Collection<? extends EntryListFilter<T>> fileFilters) {
|
||||
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>(fileFilters);
|
||||
}
|
||||
|
||||
|
||||
public CompositeEntryListFilter<T> addFilter(EntryListFilter<T> filter) {
|
||||
return this.addFilters(Collections.singletonList(filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filters one or more new filters to add
|
||||
* @return this CompositeFileFilter instance with the added filters
|
||||
* @see #addFilters(Collection)
|
||||
*/
|
||||
public CompositeEntryListFilter<T> addFilters(EntryListFilter<T>... filters) {
|
||||
return addFilters(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not thread safe. Only a single thread may add filters at a time.
|
||||
* <p/>
|
||||
* Add the new filters to this CompositeFileFilter while maintaining the existing filters.
|
||||
*
|
||||
* @param filtersToAdd a list of filters to add
|
||||
* @return this CompositeEntryListFilter instance with the added filters
|
||||
*/
|
||||
public CompositeEntryListFilter<T> addFilters(Collection<? extends EntryListFilter<T>> filtersToAdd) {
|
||||
for (EntryListFilter<? extends T> elf : filtersToAdd) {
|
||||
if (elf instanceof InitializingBean) {
|
||||
try {
|
||||
((InitializingBean) elf).afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.fileFilters.addAll(filtersToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<T> filterEntries(T[] entries) {
|
||||
Assert.notNull(entries, "'files' should not be null");
|
||||
List<T> leftOver = Arrays.asList(entries);
|
||||
for (EntryListFilter<T> fileFilter : this.fileFilters) {
|
||||
T[] ts = (T[]) leftOver.toArray();
|
||||
leftOver = fileFilter.filterEntries(ts);
|
||||
}
|
||||
return leftOver;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Strategy interface for filtering entries representing files on a local or remote file system. This is a generic
|
||||
* variant of FileListFilter that also works with references to remote files.
|
||||
* <p/>
|
||||
* Implementations must be thread safe.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Iwein Fuld
|
||||
* @since 2.0
|
||||
* @see org.springframework.integration.file.filters.FileListFilter
|
||||
*/
|
||||
public interface EntryListFilter<T> {
|
||||
|
||||
/**
|
||||
* Filters out entries and returns the entries that are left in a list, or an
|
||||
* empty list when null is passed in.
|
||||
*/
|
||||
List<T> filterEntries(T[] entries);
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.file.entries;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filters a listing of entries (T) by qualifying their 'name' (as determined by {@link org.springframework.integration.file.entries.EntryNameExtractor})
|
||||
* against a regular expression (an instance of {@link java.util.regex.Pattern})
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
* @param <T> the type of entry
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PatternMatchingEntryListFilter<T> extends AbstractEntryListFilter<T> implements InitializingBean {
|
||||
|
||||
private volatile EntryNameExtractor<T> entryNameExtractor;
|
||||
|
||||
private volatile Pattern pattern;
|
||||
|
||||
private volatile String patternExpression;
|
||||
|
||||
|
||||
public PatternMatchingEntryListFilter(EntryNameExtractor<T> entryNameExtractor, String pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.patternExpression = pattern;
|
||||
}
|
||||
|
||||
public PatternMatchingEntryListFilter(EntryNameExtractor<T> entryNameExtractor, Pattern pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
|
||||
public void setEntryNameExtractor(EntryNameExtractor<T> entryNameExtractor) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
}
|
||||
|
||||
public void setPattern(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public void setPatternExpression(String patternExpression) {
|
||||
this.patternExpression = patternExpression;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (StringUtils.hasText(this.patternExpression) && (pattern == null)) {
|
||||
this.pattern = Pattern.compile(this.patternExpression);
|
||||
}
|
||||
Assert.notNull(this.entryNameExtractor, "'entryNameExtractor' must not be null!");
|
||||
Assert.notNull(this.pattern, "'pattern' must not be null!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(T entry) {
|
||||
return (entry != null) && this.pattern.matcher(this.entryNameExtractor.getName(entry)).matches();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
|
||||
|
||||
@@ -66,14 +65,13 @@ public class PatternMatchingFileListFilterTests {
|
||||
new File("/some/path/bar.not")
|
||||
};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(this.fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
PatternMatchingFileListFilter<File> filter = new PatternMatchingFileListFilter<File>(this.fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(2, accepted.size());
|
||||
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
|
||||
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternEditorInContext() {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
||||
<bean id="filter" class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.file.entries.FileEntryNamer"/>
|
||||
</constructor-arg>
|
||||
|
||||
Reference in New Issue
Block a user