Class FastPathResolver

java.lang.Object
nonapi.io.github.classgraph.utils.FastPathResolver

public final class FastPathResolver extends Object
Resolve relative paths and URLs/URIs against a base path in a way that is faster than Java's URL/URI parser (and much faster than Path), while aiming for cross-platform compatibility, and hopefully in particular being robust to the many forms of Windows path weirdness.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    normalizePath(String path, boolean isFileOrJarURL)
    Parse percent encoding, e.g. "%20" -> " "; convert '/' or '\\' to SEP; remove trailing separator char if present.
    static String
    resolve(String pathStr)
    Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions.
    static String
    resolve(String resolveBasePath, String relativePath)
    Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions; resolve relative paths relative to resolveBasePath.

    Methods inherited from class Object

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

    • normalizePath

      public static String normalizePath(String path, boolean isFileOrJarURL)
      Parse percent encoding, e.g. "%20" -> " "; convert '/' or '\\' to SEP; remove trailing separator char if present.
      Parameters:
      path - The path to normalize.
      isFileOrJarURL - True if this is a "file:" or "jar:" URL.
      Returns:
      The normalized path.
    • resolve

      public static String resolve(String resolveBasePath, String relativePath)
      Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions; resolve relative paths relative to resolveBasePath.
      Parameters:
      resolveBasePath - The base path.
      relativePath - The path to resolve relative to the base path.
      Returns:
      The resolved path.
    • resolve

      public static String resolve(String pathStr)
      Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions. Returns null if relativePathStr is an "http(s):" path.
      Parameters:
      pathStr - The path to resolve.
      Returns:
      The resolved path.