Package de.dlr.proseo.storagemgr.utils
Class PathConverter
java.lang.Object
de.dlr.proseo.storagemgr.utils.PathConverter
A set of methods to convert and manipulate file paths based on different
conventions and requirements. It handles Windows paths, Linux paths, and S3
paths, and offers functionality to work with base paths and relative paths.
- Author:
- Denys Chaykovskiy
-
Constructor Summary
ConstructorsConstructorDescriptionPathConverter(PathConverter pathConverter) Copy constructorPathConverter(String path) Simple constructor with a pathPathConverter(String beginPath, String endPath) Constructor to merge two pathsPathConverter(String beginPath, String middlePath, String endPath) Constructor to merge three pathsPathConverter(String path, List<String> basePaths) Constructor with path and base paths, which will be used to create relative path -
Method Summary
Modifier and TypeMethodDescriptionAdds the S3 prefix to the path.Adds a slash at the beginning of the path.Adds a slash at the end of the path.Converts backslashes to slashes in the path.Fixes the absolute path by adding a slash at the end for directories and a slash at the beginning for Linux paths.Gets the file name from the path.Gets the first folder from the path.getPath()Gets the current path.Gets the relative path from the path using the base path list.Gets the storage type (S3 or POSIX) from the path.booleanChecks if the path has any base paths.booleanChecks if the path is a directory.booleanChecks if the path is a Linux path.booleanisS3Path()Checks if the path is an S3 path.booleanChecks if the path is a Windows path.Normalizes the Windows path by removing the leading slash.Converts the path to a compatible S3 path by replacing ":" in Windows paths.Removes the base paths from the path.Removes the bucket as the first folder from the path.Removes the first folder from the path.Removes the file system prefixes from the path.Removes the leading slash from the path.Converts the S3 path to a compatible POSIX path by restoring ":" in Windows paths.booleanChecks if the path starts with a slash (absolute path).
-
Constructor Details
-
PathConverter
Simple constructor with a path- Parameters:
path- The path
-
PathConverter
Constructor to merge two paths- Parameters:
beginPath- The beginning of the pathendPath- The end of the path
-
PathConverter
Constructor to merge three paths- Parameters:
beginPath- The beginning of the pathmiddlePath- The middle of the pathendPath- The end of the path
-
PathConverter
Constructor with path and base paths, which will be used to create relative path- Parameters:
path- The pathbasePaths- The base paths used for relative paths
-
PathConverter
Copy constructor- Parameters:
pathConverter- The PathConverter object to be copied
-
-
Method Details
-
getPath
Gets the current path.- Returns:
- The path
-
convertToSlash
Converts backslashes to slashes in the path.- Returns:
- A new PathConverter object with the converted path
-
getFirstFolder
Gets the first folder from the path.- Returns:
- A new PathConverter object representing the first folder
-
removeFirstFolder
Removes the first folder from the path.- Returns:
- A new PathConverter object without the first folder
-
isS3Path
public boolean isS3Path()Checks if the path is an S3 path.- Returns:
- true if the path is an S3 path, false otherwise
-
removeFsPrefix
Removes the file system prefixes from the path.- Returns:
- A new PathConverter object without the file system prefixes
-
removeBasePaths
Removes the base paths from the path.- Returns:
- A new PathConverter object without the base paths
-
hasBasePaths
public boolean hasBasePaths()Checks if the path has any base paths.- Returns:
- true if the path has any base paths, false otherwise
-
removeBucket
Removes the bucket as the first folder from the path.- Returns:
- A new PathConverter object without the bucket as the first folder
-
removeLeftSlash
Removes the leading slash from the path.- Returns:
- A new PathConverter object without the leading slash
-
startsWithSlash
public boolean startsWithSlash()Checks if the path starts with a slash (absolute path).- Returns:
- true if the path starts with a slash, false otherwise
-
addSlashAtEnd
Adds a slash at the end of the path.- Returns:
- A new PathConverter object with a slash at the end of the path
-
fixAbsolutePath
Fixes the absolute path by adding a slash at the end for directories and a slash at the beginning for Linux paths.- Returns:
- A new PathConverter object with the fixed absolute path
-
isDirectory
public boolean isDirectory()Checks if the path is a directory.- Returns:
- true if the path is a directory, false otherwise
-
addSlashAtBegin
Adds a slash at the beginning of the path.- Returns:
- A new PathConverter object with a slash at the beginning of the path
-
isWindowsPath
public boolean isWindowsPath()Checks if the path is a Windows path.- Returns:
- true if the path is a Windows path, false otherwise
-
isLinuxPath
public boolean isLinuxPath()Checks if the path is a Linux path.- Returns:
- true if the path is a Linux path, false otherwise
-
posixToS3Path
Converts the path to a compatible S3 path by replacing ":" in Windows paths.- Returns:
- A new PathConverter object with the S3-compatible path
-
s3ToPosixPath
Converts the S3 path to a compatible POSIX path by restoring ":" in Windows paths.- Returns:
- A new PathConverter object with the POSIX-compatible path
-
getRelativePath
Gets the relative path from the path using the base path list.- Returns:
- The relative path from the path using the base path list
-
addS3Prefix
Adds the S3 prefix to the path.- Returns:
- The path with the S3 prefix
-
getFileName
Gets the file name from the path.- Returns:
- The file name
-
getStorageType
Gets the storage type (S3 or POSIX) from the path.- Returns:
- The storage type
-
normalizeWindowsPath
Normalizes the Windows path by removing the leading slash.- Returns:
- The normalized Windows path
-