Package com.aoindustries.io
Class FilesystemIterator
- java.lang.Object
-
- com.aoindustries.io.FilesystemIterator
-
- All Implemented Interfaces:
Comparable<FilesystemIterator>
public class FilesystemIterator extends Object implements Comparable<FilesystemIterator>
Iterates through all of the files in a file system.- Author:
- AO Industries, Inc.
-
-
Constructor Summary
Constructors Constructor Description FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules)Constructs an iterator without any filename conversions and starting at all roots.FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, boolean isPreorder, boolean isSorted)Constructs an iterator without any filename conversions and starting at all roots.FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, String startPath)Constructs a file system iterator with the provided rules and conversion.FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, String startPath, boolean isPreorder, boolean isSorted)Constructs a file system iterator with the provided rules and conversion.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(FilesystemIterator other)Iterator<String>getFilenameIterator()Gets an iterator of filenames.protected String[]getFilesystemRoots()Gets the file system roots.FilegetNextFile()Gets the next file from the iterator ornullif the iterator has completed the iteration of the file system.intgetNextFiles(File[] files, int batchSize)Gets the next files, up to batchSize.StringgetStartPath()Gets the start path for this iterator.protected booleanisFilesystemRoot(String filename)Determines if a path is a possible file system rootbooleanisPreorder()Gets the preorder flag for this iterator.booleanisSorted()Gets the sort flag for this iterator.
-
-
-
Constructor Detail
-
FilesystemIterator
public FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules)
Constructs an iterator without any filename conversions and starting at all roots. Performs a preorder traversal - directory before directory contents. The directories are sorted.
-
FilesystemIterator
public FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, boolean isPreorder, boolean isSorted)
Constructs an iterator without any filename conversions and starting at all roots.
-
FilesystemIterator
public FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, String startPath)
Constructs a file system iterator with the provided rules and conversion. Performs a preorder traversal - directory before directory contents. The directories are sorted.
-
FilesystemIterator
public FilesystemIterator(Map<String,FilesystemIteratorRule> rules, Map<String,FilesystemIteratorRule> prefixRules, String startPath, boolean isPreorder, boolean isSorted)
Constructs a file system iterator with the provided rules and conversion.- Parameters:
rules- the rules that will be applied during iterationstartPath- if "", all roots will be used, otherwise starts at the provided path
-
-
Method Detail
-
getNextFile
public File getNextFile() throws IOException
Gets the next file from the iterator ornullif the iterator has completed the iteration of the file system. This method is internally synchronized and is thread-safe.- Throws:
IOException
-
getNextFiles
public int getNextFiles(File[] files, int batchSize) throws IOException
Gets the next files, up to batchSize.- Returns:
- the number of files in the array, zero (0) indicates iteration has completed
- Throws:
IOException
-
getFilesystemRoots
protected String[] getFilesystemRoots() throws IOException
Gets the file system roots. It will only include the root if it has at least one backup-enabled rule. An empty rule ("") will implicitly allow all roots.- Throws:
IOException
-
isFilesystemRoot
protected boolean isFilesystemRoot(String filename) throws IOException
Determines if a path is a possible file system root- Throws:
IOException
-
getFilenameIterator
public Iterator<String> getFilenameIterator() throws IOException
Gets an iterator of filenames.- Throws:
IOException
-
getStartPath
public String getStartPath()
Gets the start path for this iterator.
-
isPreorder
public boolean isPreorder()
Gets the preorder flag for this iterator.
-
isSorted
public boolean isSorted()
Gets the sort flag for this iterator.
-
compareTo
public int compareTo(FilesystemIterator other)
- Specified by:
compareToin interfaceComparable<FilesystemIterator>
-
-