Class PathUtils


  • public class PathUtils
    extends Object
    A set of utility methods for working with storage paths
    Author:
    Eyal Schneider
    • Constructor Detail

      • PathUtils

        public PathUtils()
    • Method Detail

      • buildPath

        public static String buildPath​(String... parts)
        Builds a path from the given parts (not including protocol) Handles normalization of the path by eliminating consecutive separators, using separators between paths. and removing leading separators if needed.
        Parameters:
        parts - path parts. May be single path parts or sub paths
        Returns:
        a single path composed by the given parts
      • buildFullPath

        public static String buildFullPath​(String protocol,
                                           String... parts)
        Builds a full cloud path from the given parts. Handles normalization of the path by eliminating consecutive separators, using separators between paths. and removing leading separators if needed.
        Parameters:
        protocol - The protocol name (e.g. "gs") with no separators
        parts - path parts. May be single path parts or sub paths
        Returns:
        a single path composed by the given parts
      • buildPath

        public static String buildPath​(boolean isFolder,
                                       String... parts)
        Builds a cloud path from the given parts (not including protocol) Handles normalization of the path by eliminating consecutive separators, using separators between paths. and removing leading separators if needed.
        Parameters:
        isFolder - indicates whether the path should lead to a folder
        parts - path parts. May be single path parts or sub paths
        Returns:
        a single path composed by the given parts
      • buildPath

        public static String buildPath​(String protocol,
                                       boolean isFolder,
                                       String... parts)
        Builds a full cloud path from the given parts. Handles normalization of the path by eliminating consecutive separators, using separators between paths. and removing leading separators if needed.
        Parameters:
        protocol - The protocol name (e.g. "gs") with no separators
        isFolder - indicates whether the path should lead to a folder
        parts - path parts. May be single path parts or sub paths
        Returns:
        a single path composed by the given parts
      • getLastPathPart

        public static String getLastPathPart​(String path)
        Returns the last part of a given path. For example: 1. if the path is `/aa/bb/cc.json` the returned value would be `cc.json` s. if the path is `/aa/bb/cc` the returned value would be `cc`
        Parameters:
        path - cloud storage path
        Returns:
        a single path composed by the given parts
      • getParentPath

        public static String getParentPath​(String path)
        Parameters:
        path - a cloud storage path to extract the parent from. Assumed to include at least one path separator.
        Returns:
        the parent path
      • getProtocolFromFullyQualifiedPath

        public static String getProtocolFromFullyQualifiedPath​(String fullyQualifiedPath)
        Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the protocol name (e.g. "gs" or "s3")
        Parameters:
        fullyQualifiedPath - The path to examine
        Returns:
        protocol or null if it doesn't exist
      • getBucketNameFromFullyQualifiedPath

        public static String getBucketNameFromFullyQualifiedPath​(String fullyQualifiedPath)
        Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the bucket name.
        Parameters:
        fullyQualifiedPath - The path to examine
        Returns:
        bucket name or null if it doesn't exist
      • getKeyFromFullyQualifiedPath

        public static String getKeyFromFullyQualifiedPath​(String fullyQualifiedPath)
        Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the key.
        Parameters:
        fullyQualifiedPath - The fully qualified path ({protocol}://{bucket}/{path})
        Returns:
        key path or null if it doesn't exist
      • parseFullyQualifiedPath

        public static StoragePath parseFullyQualifiedPath​(String fullyQualifiedPath)
        Parses a fully qualified path and returns the protocol+bucket+key triplet.
        Parameters:
        fullyQualifiedPath - The fully qualified path ({protocol}://{bucket}/{path})
        Returns:
        A the storage path object, containing the 3 parsed path components