Class EnvironmentUtility



  • public final class EnvironmentUtility
    extends Object
    Utility class with helpful methods for working with a system's environment variables.
    • Method Detail

      • toAbsoluteUserHomePath

        public static String toAbsoluteUserHomePath​(String aPath)
                                             throws IllegalStateException
        This method converts a relative path to an absolute path relative to the user's home folder. In case there is no user home set in the system's environment, then an illegal state exception is thrown. If the path is an absolute path, then no modifications are applied to the absolute path and it is returned unmodified. ------------------------------------------------------------------------- ATTENTION: In case the provided path already points to an existing file, then the absolute path for that path is returned! -------------------------------------------------------------------------
        Parameters:
        aPath - The path to be converted to an absolute path in case it was a relative path.
        Returns:
        An absolute path, either the given path in case it was an absolute path or a path relative to the user's home folder.
        Throws:
        IllegalStateException - in case the user's home folder is not defined and a relative path has been provided.
      • toAbsolutePathFromEnvironment

        public static String toAbsolutePathFromEnvironment​(String aPath,
                                                           String... aEnvHomePropertyNames)
                                                    throws IllegalArgumentException
        This method converts a relative path to an absolute path relative to the path specified in the first system property provided being set with a value. In case the path provided is an absolute path, then the path is returned unmodified. case there is no such system property set in the system's environment or the value is empty, then an illegal argument exception is thrown. If the path is an absolute path, then no modifications are applied to the absolute path and it is returned unmodified. ------------------------------------------------------------------------- ATTENTION: In case the provided path already points to an existing file, then the absolute path for that path is returned! -------------------------------------------------------------------------
        Parameters:
        aPath - The path to be converted to an absolute path in case it was a relative path.
        aEnvHomePropertyNames - The names of the system properties which's value is to be used in order to resolve the path.
        Returns:
        An absolute path, either the given path in case it was an absolute path or a path relative to the specified system's property value (a folder).
        Throws:
        IllegalArgumentException - in case the system property name is not defined or is empty and a relative path has been provided.
      • toPlatformSpecificPath

        public static String toPlatformSpecificPath​(String aPath)
        This method concerts the given path to a platform specific path, mainly replacing the path separator accordingly.
        Parameters:
        aPath - The path to be converted.
        Returns:
        The converted path.