Klasse PathConverter

java.lang.Object
de.dlr.proseo.storagemgr.utils.PathConverter

public class PathConverter extends Object
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
  • Konstruktordetails

    • PathConverter

      public PathConverter(String path)
      Simple constructor with a path
      Parameter:
      path - The path
    • PathConverter

      public PathConverter(String path1, String path2)
      Constructor to merge two paths
      Parameter:
      path1 - The beginning of the path
      path2 - The end of the path
    • PathConverter

      public PathConverter(String path1, String path2, String path3)
      Constructor to merge three paths
      Parameter:
      path1 - The beginning of the path
      path2 - The middle of the path
      path3 - The end of the path
    • PathConverter

      public PathConverter(String path, List<String> basePaths)
      Constructor with path and base paths, which will be used to create relative path
      Parameter:
      path - The path
      basePaths - The base paths used for relative paths
    • PathConverter

      public PathConverter(PathConverter pathConverter)
      Copy constructor
      Parameter:
      pathConverter - The PathConverter object to be copied
  • Methodendetails

    • addBasePath

      public void addBasePath(String basePath)
      Adds a base path to the list of base paths used for relative paths.
      Parameter:
      basePath - The base path to be added
    • getPath

      public String getPath()
      Gets the current path.
      Gibt zurück:
      The path
    • convertToSlash

      public PathConverter convertToSlash()
      Converts backslashes to slashes in the path.
      Gibt zurück:
      A new PathConverter object with the converted path
    • getFirstFolder

      public PathConverter getFirstFolder()
      Gets the first folder from the path.
      Gibt zurück:
      A new PathConverter object representing the first folder
    • removeFirstFolder

      public PathConverter 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

      public PathConverter removeFsPrefix()
      Removes the file system prefixes from the path.
      Gibt zurück:
      A new PathConverter object without the file system prefixes
    • removeBasePaths

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter 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

      public PathConverter removeDoubleSlash()
      Removes double slashes from the path.
      Gibt zurück:
      A new PathConverter object with single slashes (no double slashes)
    • replaceBackslashWithSlash

      public String replaceBackslashWithSlash(String str)
      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

      public PathConverter 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

      public PathConverter addS3Prefix()
      Adds the S3 prefix to the path.
      Gibt zurück:
      The path with the S3 prefix
    • getFileName

      public String getFileName()
      Gets the file name from the path.
      Gibt zurück:
      The file name
    • getStorageType

      public StorageType getStorageType()
      Gets the storage type (S3 or POSIX) from the path.
      Gibt zurück:
      The storage type
    • normalizeWindowsPath

      public PathConverter normalizeWindowsPath()
      Normalizes the Windows path by removing the leading slash.
      Gibt zurück:
      The normalized Windows path