Package de.dlr.proseo.storagemgr.utils
Klasse 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.
- Autor:
- Denys Chaykovskiy
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungPathConverter
(PathConverter pathConverter) Copy constructorPathConverter
(String path) Simple constructor with a pathPathConverter
(String path1, String path2) Constructor to merge two pathsPathConverter
(String path1, String path2, String path3) Constructor to merge three pathsPathConverter
(String path, List<String> basePaths) Constructor with path and base paths, which will be used to create relative path -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
addBasePath
(String basePath) Adds a base path to the list of base paths used for relative paths.Adds 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.boolean
Checks if the path has any base paths.boolean
Checks if the path is a directory.boolean
Checks if the path is a Linux path.boolean
isS3Path()
Checks if the path is an S3 path.boolean
Checks if the path is a Windows path.boolean
Checks if the path is a converted Windows path for S3.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 double slashes 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.Replaces backslashes with slashes in the given string.Converts the S3 path to a compatible POSIX path by restoring ":" in Windows paths.boolean
Checks if the path starts with a slash (absolute path).
-
Konstruktordetails
-
PathConverter
Simple constructor with a path- Parameter:
path
- The path
-
PathConverter
Constructor to merge two paths- Parameter:
path1
- The beginning of the pathpath2
- The end of the path
-
PathConverter
Constructor to merge three paths- Parameter:
path1
- The beginning of the pathpath2
- The middle of the pathpath3
- The end of the path
-
PathConverter
Constructor with path and base paths, which will be used to create relative path- Parameter:
path
- The pathbasePaths
- The base paths used for relative paths
-
PathConverter
Copy constructor- Parameter:
pathConverter
- The PathConverter object to be copied
-
-
Methodendetails
-
addBasePath
Adds a base path to the list of base paths used for relative paths.- Parameter:
basePath
- The base path to be added
-
getPath
Gets the current path.- Gibt zurück:
- The path
-
convertToSlash
Converts backslashes to slashes in the path.- Gibt zurück:
- A new PathConverter object with the converted path
-
getFirstFolder
Gets the first folder from the path.- Gibt zurück:
- A new PathConverter object representing the first folder
-
removeFirstFolder
Removes the first folder from the path.- Gibt zurück:
- A new PathConverter object without the first folder
-
isS3Path
public boolean isS3Path()Checks if the path is an S3 path.- Gibt zurück:
- true if the path is an S3 path, false otherwise
-
removeFsPrefix
Removes the file system prefixes from the path.- Gibt zurück:
- A new PathConverter object without the file system prefixes
-
removeBasePaths
Removes the base paths from the path.- Gibt zurück:
- A new PathConverter object without the base paths
-
hasBasePaths
public boolean hasBasePaths()Checks if the path has any base paths.- Gibt zurück:
- true if the path has any base paths, false otherwise
-
removeBucket
Removes the bucket as the first folder from the path.- Gibt zurück:
- A new PathConverter object without the bucket as the first folder
-
removeLeftSlash
Removes the leading slash from the path.- Gibt zurück:
- A new PathConverter object without the leading slash
-
startsWithSlash
public boolean startsWithSlash()Checks if the path starts with a slash (absolute path).- Gibt zurück:
- true if the path starts with a slash, false otherwise
-
addSlashAtEnd
Adds a slash at the end of the path.- Gibt zurück:
- 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.- Gibt zurück:
- A new PathConverter object with the fixed absolute path
-
isDirectory
public boolean isDirectory()Checks if the path is a directory.- Gibt zurück:
- true if the path is a directory, false otherwise
-
addSlashAtBegin
Adds a slash at the beginning of the path.- Gibt zurück:
- 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.- Gibt zurück:
- true if the path is a Windows path, false otherwise
-
isLinuxPath
public boolean isLinuxPath()Checks if the path is a Linux path.- Gibt zurück:
- true if the path is a Linux path, false otherwise
-
posixToS3Path
Converts the path to a compatible S3 path by replacing ":" in Windows paths.- Gibt zurück:
- A new PathConverter object with the S3-compatible path
-
s3ToPosixPath
Converts the S3 path to a compatible POSIX path by restoring ":" in Windows paths.- Gibt zurück:
- A new PathConverter object with the POSIX-compatible path
-
isWinPathInS3
public boolean isWinPathInS3()Checks if the path is a converted Windows path for S3.- Gibt zurück:
- true if the path is a converted Windows path for S3, false otherwise
-
removeDoubleSlash
Removes double slashes from the path.- Gibt zurück:
- A new PathConverter object with single slashes (no double slashes)
-
replaceBackslashWithSlash
Replaces backslashes with slashes in the given string.- Parameter:
str
- The string to be modified- Gibt zurück:
- The modified string with slashes instead of backslashes
-
getRelativePath
Gets the relative path from the path using the base path list.- Gibt zurück:
- The relative path from the path using the base path list
-
addS3Prefix
Adds the S3 prefix to the path.- Gibt zurück:
- The path with the S3 prefix
-
getFileName
Gets the file name from the path.- Gibt zurück:
- The file name
-
getStorageType
Gets the storage type (S3 or POSIX) from the path.- Gibt zurück:
- The storage type
-
normalizeWindowsPath
Normalizes the Windows path by removing the leading slash.- Gibt zurück:
- The normalized Windows path
-