Class PathUtils


  • public final class PathUtils
    extends java.lang.Object
    A reusable utility class for file paths.
    Since:
    2.0.13
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String stringToPathSegment​(java.lang.String string)
      Method that makes sure that passed in string is valid "path segment" string.
      static void validateArtifactComponents​(org.eclipse.aether.artifact.Artifact artifact)
      Validates all coordinate components of an Artifact.
      static void validateDotSeparatedPathComponent​(java.lang.String value, java.lang.String label)
      Validates a coordinate component that is expanded into multiple path segments by replacing each dot with a path separator, like the group ID is.
      static void validateMetadataComponents​(org.eclipse.aether.metadata.Metadata metadata)
      Validates all coordinate components of a Metadata.
      static void validatePathComponent​(java.lang.String value, java.lang.String label)
      Validates that a coordinate component does not contain path traversal sequences or path separator characters that could cause the composed path to escape the local repository directory.
      • Methods inherited from class java.lang.Object

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

      • stringToPathSegment

        public static java.lang.String stringToPathSegment​(java.lang.String string)
        Method that makes sure that passed in string is valid "path segment" string. It achieves it by potentially changing it, replacing illegal characters in it with legal ones.

        Note: this method considers empty string as "valid path segment", it is caller duty to ensure empty string is not used as path segment alone.

        This method is simplistic on purpose, and if frequently used, best if results are cached (per session)

      • validatePathComponent

        public static void validatePathComponent​(java.lang.String value,
                                                 java.lang.String label)
        Validates that a coordinate component does not contain path traversal sequences or path separator characters that could cause the composed path to escape the local repository directory.
        Since:
        2.0.21
      • validateDotSeparatedPathComponent

        public static void validateDotSeparatedPathComponent​(java.lang.String value,
                                                             java.lang.String label)
        Validates a coordinate component that is expanded into multiple path segments by replacing each dot with a path separator, like the group ID is. Beside the checks done by validatePathComponent(String, String), it rejects values containing empty dot-separated segments (leading, trailing or consecutive dots), as the expansion of such values does not compose a valid relative path.
        Since:
        2.0.23