@@ -0,0 +1,2112 @@
+public final class MultiDirFileIterator implements Iterator%3CFile%3E %7B%0A%0A%09private final List%3CFileIterator%3E fileIterators = (List%3CFileIterator%3E) Collections%0A%09%09%09.synchronizedList(new ArrayList%3CFileIterator%3E());%0A%09private final AtomicInteger currentPos = new AtomicInteger(0);%0A%09private final AtomicInteger fileIteratorsSize = new AtomicInteger(0);%0A%09private final FileFilter filter;%0A%09private final Lock iteratorLock = new ReentrantLock();%0A%09private final FileReferenceHolder fileHolder = new FileReferenceHolder();%0A%0A%09public ConcurrentMultiDirFileIterator(FileFilter filterp) %7B%0A%09%09this.filter = filterp;%0A%09%7D%0A%0A%09public synchronized void addDirectory(File dir) %7B%0A%09%09if (dir == null %7C%7C !dir.isDirectory()) %7B%0A%09%09%09throw new IllegalArgumentException(%22Only Directory allowed%22);%0A%09%09%7D%0A%09%09fileIterators.add(FileIterator.createFileIterator(dir, this.filter));%0A%09%09fileIteratorsSize.incrementAndGet();%0A%09%7D%0A%0A%09@Override%0A%09public boolean hasNext() %7B%0A%09%09fileHolder.setFile(getNext());%0A%09%09return fileHolder.getFile() != null;%0A%09%7D%0A%0A%09public void tryLock() %7B%0A%09%09this.iteratorLock.lock();%0A%09%7D%0A%0A%09protected File getNext() %7B%0A%09%09File f = null;%0A%09%09for (int i = 0; i %3C fileIteratorsSize.get(); i++) %7B%0A%09%09%09FileIterator fiter = null;%0A%09%09%09if (fileIteratorsSize.get() %3E 0) %7B%0A%09%09%09%09currentPos.set(currentPos.get() %25 fileIteratorsSize.get());%0A%09%09%09%7D%0A%09%09%09if (currentPos.get() %3C fileIteratorsSize.get()) %7B%0A%09%09%09%09fiter = fileIterators.get(currentPos.getAndIncrement());%0A%09%09%09%7D%0A%09%09%09if (fiter == null) %7B%0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09if (fiter.hasNext()) %7B%0A%09%09%09%09f = fiter.next();%0A%09%09%09%09break;%0A%09%09%09%7D else %7B%0A%09%09%09%09fiter = FileIterator.createFileIterator(fiter.getDir(),%0A%09%09%09%09%09%09this.filter);%0A%09%09%09%09fileIterators%0A%09%09%09%09%09%09.set((currentPos.get() - 1) %25 fileIteratorsSize.get(),%0A%09%09%09%09%09%09%09%09fiter);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return f;%0A%09%7D%0A%0A%09@Override%0A%09public File next() %7B%0A%09%09File f = fileHolder.getFile();%0A%09%09return f;%0A%09%7D%0A%0A%09public void unLock() %7B%0A%09%09this.iteratorLock.unlock();%0A%09%7D%0A%0A%09public void abort() %7B%0A%09%09for (FileIterator fiter : this.fileIterators) %7B%0A%09%09%09fiter.abort();%0A%09%09%7D%0A%09%09iteratorLock.unlock();%0A%09%7D%0A%0A%09@Override%0A%09public void remove() %7B%0A%09%09throw new IllegalStateException(%0A%09%09%09%09%22Remove Operation is not allowed for FileIterator%22);%0A%09%7D%0A%0A%7D%0A

Create MultiDirFileIterator.java