Package org.pipecraft.infra.storage
Class PathUtils
- java.lang.Object
-
- org.pipecraft.infra.storage.PathUtils
-
public class PathUtils extends Object
A set of utility methods for working with storage paths- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description PathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbuildFullPath(String protocol, String... parts)Builds a full cloud path from the given parts.static StringbuildPath(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.static StringbuildPath(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.static StringbuildPath(String protocol, boolean isFolder, String... parts)Builds a full cloud path from the given parts.static StringgetBucketNameFromFullyQualifiedPath(String fullyQualifiedPath)Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the bucket name.static StringgetKeyFromFullyQualifiedPath(String fullyQualifiedPath)Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the key.static StringgetLastPathPart(String path)Returns the last part of a given path.static StringgetParentPath(String path)static StringgetProtocolFromFullyQualifiedPath(String fullyQualifiedPath)Gets a fully qualified path ({protocol}://{bucket}/{path}) and returns the protocol name (e.g.static StoragePathparseFullyQualifiedPath(String fullyQualifiedPath)Parses a fully qualified path and returns the protocol+bucket+key triplet.
-
-
-
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 separatorsparts- 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 folderparts- 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 separatorsisFolder- indicates whether the path should lead to a folderparts- 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
-
-