Revision 51722
Added by Alessia Bardi about 6 years ago
FileSystemIterator.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import com.google.common.collect.Iterators; |
11 | 11 |
import com.google.common.collect.Sets; |
12 |
import eu.dnetlib.data.collector.ThreadSafeIterator; |
|
13 | 12 |
import org.apache.commons.io.FilenameUtils; |
14 | 13 |
import org.apache.commons.logging.Log; |
15 | 14 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
18 | 17 |
* Class enabling lazy & recursive iteration of a filesystem tree. The iterator iterates over file paths. |
19 | 18 |
* |
20 | 19 |
* @author Andrea |
20 |
* |
|
21 | 21 |
*/ |
22 |
public class FileSystemIterator extends ThreadSafeIterator {
|
|
22 |
public class FileSystemIterator implements Iterator<String> {
|
|
23 | 23 |
|
24 |
/** |
|
25 |
* The logger |
|
26 |
*/ |
|
24 |
/** The logger */ |
|
27 | 25 |
private static final Log log = LogFactory.getLog(FileSystemIterator.class); |
28 | 26 |
|
29 | 27 |
private Set<String> extensions; |
... | ... | |
42 | 40 |
} |
43 | 41 |
|
44 | 42 |
@Override |
45 |
public boolean doHasNext() {
|
|
43 |
public boolean hasNext() {
|
|
46 | 44 |
return current != null; |
47 | 45 |
} |
48 | 46 |
|
49 | 47 |
@Override |
50 |
public String doNext() {
|
|
48 |
public synchronized String next() {
|
|
51 | 49 |
String pivot = new String(current); |
52 | 50 |
current = walkTillNext(); |
53 | 51 |
log.debug("Returning: " + pivot); |
54 | 52 |
return pivot; |
55 | 53 |
} |
56 | 54 |
|
55 |
@Override |
|
56 |
public void remove() {} |
|
57 |
|
|
57 | 58 |
/** |
58 | 59 |
* Walk the filesystem recursively until it finds a candidate. Strategies: a) For any directory found during the walk, an iterator is |
59 | 60 |
* built and concat to the main one; b) Any file is checked against admitted extensions |
... | ... | |
81 | 82 |
} |
82 | 83 |
return null; |
83 | 84 |
} |
84 |
} |
|
85 |
} |
Also available in: Unified diff
Reverted filesystem plugin to the first implementation that does not use FileDirectoryStream: files were left open causing Too many open files errors