Class CollectionGlob

  • All Implemented Interfaces:
    Closeable, AutoCloseable, MCollection

    public class CollectionGlob
    extends CollectionAbstract
    A MCollection defined by a glob filter. Experimental. From http://blog.eyallupu.com/2011/11/java-7-working-with-directories.html The 'glob' Syntax The glob (stands for globbing) syntax is a 'simplified' form of regular expressions with awareness to path components (directories), the syntax is composed of the following syntactic tokens: 1) The '*' character matches zero or more characters from the path elements without crossing directory boundaries (unlike regular expression this is not a Kleene star and it has nothing to do with the preceding part of the expression) 2) The '**' characters match zero or more characters crossing directory boundaries 3) The '?' character matches exactly one character of a name component 4) '[' and ']' can be used to match a single character in the path name from a set of characters '-' (hyphen) can be used to specify a range of characters. If hyphen has to be included in the characters set it must be the first in the set '!' as the first character in the set can be used as a negation expression 5) '{' and '}' can group sub patterns, the group matches if any of the sub patterns matches (comma is used to separate between the groups) 6 ) The dot '.' character represents a dot (unlike regular expressions in which a dot is a replacement for any character) 7) and finally: special characters escaping is done using backslash The '**' expression is the only one to cross directory boundaries, all other expressions are bound within a single element (either a directory or a filename), below is a sample usage of PathMatcher followed by few pattern examples:
    Since:
    5/19/14
    • Constructor Detail

      • CollectionGlob

        public CollectionGlob​(String collectionName,
                              String glob,
                              org.slf4j.Logger logger)
    • Method Detail

      • close

        public void close()
        Description copied from interface: MCollection
        Close and release any resources. Do not make further calls on this object.
      • getFilesSorted

        public Iterable<MFile> getFilesSorted()
                                       throws IOException
        Description copied from interface: MCollection
        Get the current collection of MFile. if hasDateExtractor() == true, these will be sorted by Date, otherwise by path.
        Returns:
        current collection of MFile as an Iterable.
        Throws:
        IOException
      • getFileIterator

        public CloseableIterator<MFile> getFileIterator()
                                                 throws IOException
        Description copied from interface: MCollection
        Get the current collection of MFile, no guaranteed order. May be faster than getFilesSorted() for large collections, use when order is not important.
         try (CloseableIterator iter = getFileIterator()) {
           while (iter.hasNext()) {
             MFile file = iter.next();
           }
         }
         
        Returns:
        current collection of MFile as an CloseableIterator.
        Throws:
        IOException