Class EnvironmentUtility


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String toAbsolutePathFromEnvironment​(java.lang.String aPath, java.lang.String... aEnvHomePropertyNames)
      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.
      static java.lang.String toAbsoluteUserHomePath​(java.lang.String aPath)
      This method converts a relative path to an absolute path relative to the user's home folder.
      static java.lang.String toPlatformSpecificPath​(java.lang.String aPath)
      This method concerts the given path to a platform specific path, mainly replacing the path separator accordingly.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toAbsoluteUserHomePath

        public static java.lang.String toAbsoluteUserHomePath​(java.lang.String aPath)
                                                       throws java.lang.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:
        java.lang.IllegalStateException - in case the user's home folder is not defined and a relative path has been provided.
      • toAbsolutePathFromEnvironment

        public static java.lang.String toAbsolutePathFromEnvironment​(java.lang.String aPath,
                                                                     java.lang.String... aEnvHomePropertyNames)
                                                              throws java.lang.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:
        java.lang.IllegalArgumentException - in case the system property name is not defined or is empty and a relative path has been provided.
      • toPlatformSpecificPath

        public static java.lang.String toPlatformSpecificPath​(java.lang.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.