Class PathUtils


  • public final class PathUtils
    extends java.lang.Object
    General helpful path utility methods.
    Author:
    David M. Lloyd
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String basicModuleNameToPath​(java.lang.String moduleName)
      Convert a "basic" module name to a relative path specification.
      static java.lang.String canonicalize​(java.lang.String path)
      Canonicalize the given path.
      static java.lang.String fileNameOfPath​(java.lang.String path)
      Get the file name (last) segment of the given path.
      static <T extends java.util.Collection<? super java.lang.String>>
      T
      filterPaths​(java.lang.Iterable<java.lang.String> source, PathFilter filter, T target)
      Filter the paths from source into target using filter.
      static java.util.Set<java.lang.String> getPathSet​(java.lang.ClassLoader classLoader)
      Attempt to get a set of all paths defined directly by the given class loader.
      static boolean isChild​(java.lang.String parent, java.lang.String child)
      Determine whether one path is a child of another.
      static boolean isDirectChild​(java.lang.String parent, java.lang.String child)
      Determine whether one path is a direct (or immediate) child of another.
      static boolean isRelative​(java.lang.String path)
      Determine whether a path name is relative.
      static boolean isSeparator​(char ch)
      Determine whether the given character is a / or a platform-specific separator.
      static java.lang.String relativize​(java.lang.String path)
      Relativize the given path.
      static java.lang.String toGenericSeparators​(java.lang.String original)
      Get the given path name with OS-specific separators replaced with the generic / separator character.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • filterPaths

        public static <T extends java.util.Collection<? super java.lang.String>> T filterPaths​(java.lang.Iterable<java.lang.String> source,
                                                                                               PathFilter filter,
                                                                                               T target)
        Filter the paths from source into target using filter.
        Type Parameters:
        T - the collection type
        Parameters:
        source - the source paths
        filter - the filter to apply
        target - the destination for filtered paths
        Returns:
        the target set
      • getPathSet

        public static java.util.Set<java.lang.String> getPathSet​(java.lang.ClassLoader classLoader)
        Attempt to get a set of all paths defined directly by the given class loader. If the path set cannot be ascertained, null is returned.
        Parameters:
        classLoader - the class loader to inspect
        Returns:
        the set, or null if the paths could not be determined
      • relativize

        public static java.lang.String relativize​(java.lang.String path)
        Relativize the given path. Removes any leading / segments from the path.
        Parameters:
        path - the path to relativize
        Returns:
        the relative path
      • fileNameOfPath

        public static java.lang.String fileNameOfPath​(java.lang.String path)
        Get the file name (last) segment of the given path.
        Parameters:
        path - the path name
        Returns:
        the file name
      • canonicalize

        public static java.lang.String canonicalize​(java.lang.String path)
        Canonicalize the given path. Removes all . and .. segments from the path.
        Parameters:
        path - the relative or absolute possibly non-canonical path
        Returns:
        the canonical path
      • isChild

        public static boolean isChild​(java.lang.String parent,
                                      java.lang.String child)
        Determine whether one path is a child of another.
        Parameters:
        parent - the parent path
        child - the child path
        Returns:
        true if the child is truly a child of parent
      • isDirectChild

        public static boolean isDirectChild​(java.lang.String parent,
                                            java.lang.String child)
        Determine whether one path is a direct (or immediate) child of another.
        Parameters:
        parent - the parent path
        child - the child path
        Returns:
        true if the child is truly a direct child of parent
      • toGenericSeparators

        public static java.lang.String toGenericSeparators​(java.lang.String original)
        Get the given path name with OS-specific separators replaced with the generic / separator character.
        Parameters:
        original - the original string
        Returns:
        the same string with OS-specific separators replaced with /
      • isRelative

        public static boolean isRelative​(java.lang.String path)
        Determine whether a path name is relative.
        Parameters:
        path - the path name
        Returns:
        true if it is relative
      • isSeparator

        public static boolean isSeparator​(char ch)
        Determine whether the given character is a / or a platform-specific separator.
        Parameters:
        ch - the character to test
        Returns:
        true if it is a separator
      • basicModuleNameToPath

        public static java.lang.String basicModuleNameToPath​(java.lang.String moduleName)
        Convert a "basic" module name to a relative path specification.
        Parameters:
        moduleName - the basic module name
        Returns:
        the path specification, or null if the name is not valid