Class PathUtils

java.lang.Object
dev.prozilla.pine.common.system.PathUtils

public final class PathUtils extends Object
Utility class for handling path strings.
  • Method Details

    • onlyLeadingSlash

      public static String onlyLeadingSlash(String path)
      Transforms the path so it has a leading slash and no trailing slash.
      Parameters:
      path - The original path
      Returns:
      The path with only a leading slash.
    • onlyTrailingSlash

      public static String onlyTrailingSlash(String path)
      Transforms the path so it has a trailing slash and no leading slash.
      Parameters:
      path - The original path
      Returns:
      The path with only a trailing slash.
    • removeLeadingSlash

      public static String removeLeadingSlash(String path)
      Removes a leading slash from a path if there is one.
      Parameters:
      path - The original path
      Returns:
      Path without leading slash
    • addLeadingSlash

      public static String addLeadingSlash(String path)
      Adds a leading slash to a path if there isn't one.
      Parameters:
      path - The original path
      Returns:
      Path with leading slash
    • removeTrailingSlash

      public static String removeTrailingSlash(String path)
      Removes a trailing slash from a path if there is one.
      Parameters:
      path - The original path
      Returns:
      Path without trailing slash
    • addTrailingSlash

      public static String addTrailingSlash(String path)
      Adds a trailing slash to a path if there isn't one.
      Parameters:
      path - The original path
      Returns:
      Path with trailing slash
    • normalizePath

      public static String normalizePath(String path)
      Normalizes a path by removing prefixes and replacing separators.
      Parameters:
      path - The original path
      Returns:
      The normalized path
    • relativizePath

      public static String relativizePath(String path)
      Returns a path relative to the source root.
      Parameters:
      path - The original path
      Returns:
      The path relative to the source root
    • createLink

      public static String createLink(String path)
      Creates a clickable filepath URL.
      Parameters:
      path - The path of the file or folder
      Returns:
      A link to the file or folder
    • getFileExtension

      public static String getFileExtension(String path)
      Returns the file extension of a given path.
      Parameters:
      path - The path of a file
      Returns:
      The file extension, or an empty string if path is null or there is no file extension.