Class ResourceEnumeration

  • All Implemented Interfaces:
    java.util.Enumeration<java.net.URL>

    final class ResourceEnumeration
    extends java.lang.Object
    implements java.util.Enumeration<java.net.URL>
    Enumeration of resources found by scanning JARs and directories.
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceEnumeration​(java.lang.String subPath, java.lang.String glob, boolean recurse, java.net.URL[] urls)
      Creates an Enumeration that scans the given URLs for resources matching the globbed pattern.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.net.URL findResource​(java.lang.String name)
      Returns a URL pointing to the named resource underneath the current search URL.
      boolean hasMoreElements()  
      private boolean matchesRequest​(java.lang.String entryName)
      Compares the given entry name against the normalized search path and compiled glob pattern.
      java.net.URL nextElement()  
      (package private) static java.lang.String normalizeSearchPath​(java.lang.String path)
      Normalizes the initial search path by removing any duplicate or initial slashes.
      private java.util.Iterator<java.lang.String> scan​(java.net.URL url)
      Returns the appropriate Iterator to iterate over the contents of the given URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Enumeration

        asIterator
    • Field Detail

      • NO_ENTRIES

        private static final java.util.Iterator<java.lang.String> NO_ENTRIES
      • urls

        private final java.net.URL[] urls
      • subPath

        private final java.lang.String subPath
      • globPattern

        private final java.lang.Object globPattern
      • recurse

        private final boolean recurse
      • index

        private int index
      • currentURL

        private java.net.URL currentURL
      • isFolder

        private boolean isFolder
      • entryNames

        private java.util.Iterator<java.lang.String> entryNames
      • nextEntryName

        private java.lang.String nextEntryName
    • Constructor Detail

      • ResourceEnumeration

        ResourceEnumeration​(java.lang.String subPath,
                            java.lang.String glob,
                            boolean recurse,
                            java.net.URL[] urls)
        Creates an Enumeration that scans the given URLs for resources matching the globbed pattern.
        Parameters:
        subPath - An optional path to begin the search from
        glob - The globbed basename pattern
        recurse - When true search paths below the initial search point; otherwise don't
        urls - The URLs containing resources
    • Method Detail

      • hasMoreElements

        public boolean hasMoreElements()
        Specified by:
        hasMoreElements in interface java.util.Enumeration<java.net.URL>
      • nextElement

        public java.net.URL nextElement()
        Specified by:
        nextElement in interface java.util.Enumeration<java.net.URL>
      • normalizeSearchPath

        static java.lang.String normalizeSearchPath​(java.lang.String path)
        Normalizes the initial search path by removing any duplicate or initial slashes.
        Parameters:
        path - The path to normalize
        Returns:
        Normalized search path
      • scan

        private java.util.Iterator<java.lang.String> scan​(java.net.URL url)
        Returns the appropriate Iterator to iterate over the contents of the given URL.
        Parameters:
        url - The containing URL
        Returns:
        Iterator that iterates over resources contained inside the given URL
      • findResource

        private java.net.URL findResource​(java.lang.String name)
                                   throws java.net.MalformedURLException
        Returns a URL pointing to the named resource underneath the current search URL.
        Parameters:
        name - The resource name
        Returns:
        URL for the resource
        Throws:
        java.net.MalformedURLException
      • matchesRequest

        private boolean matchesRequest​(java.lang.String entryName)
        Compares the given entry name against the normalized search path and compiled glob pattern.
        Parameters:
        entryName - The entry name
        Returns:
        true if the given name matches the search criteria; otherwise false