Class OsUtils

java.lang.Object
org.apache.sshd.common.util.OsUtils

public final class OsUtils extends Object
Operating system dependent utility methods.
  • Field Details

  • Constructor Details

    • OsUtils

      private OsUtils()
  • Method Details

    • isUNIX

      public static boolean isUNIX()
      Returns:
      true if the host is a UNIX system (and not Windows).
    • isOSX

      public static boolean isOSX()
      Returns:
      true if the host is a OSX (and not Windows or Unix).
    • isWin32

      public static boolean isWin32()
      Returns:
      true if the host is Windows (and not UNIX).
      See Also:
    • setOS

      public static void setOS(String os)
      Can be used to enforce Win32 or Linux report from isWin32(), isOSX() or isUNIX()
      Parameters:
      os - The value to set - if null then O/S type is auto-detected
      See Also:
    • getOS

      private static String getOS()
      Returns:
      The resolved O/S type string if not already set (lowercase)
    • resolveDefaultInteractiveShellCommand

      public static String resolveDefaultInteractiveShellCommand()
    • resolveDefaultInteractiveShellCommand

      public static String resolveDefaultInteractiveShellCommand(boolean winOS)
    • resolveDefaultInteractiveCommandElements

      public static List<String> resolveDefaultInteractiveCommandElements()
    • resolveDefaultInteractiveCommandElements

      public static List<String> resolveDefaultInteractiveCommandElements(boolean winOS)
    • getCurrentUser

      public static String getCurrentUser()
      Get current user name
      Returns:
      Current user
      See Also:
    • getCanonicalUser

      public static String getCanonicalUser(String user)
      Remove Windows domain and/or group prefix as well as "(User);&quot suffix
      Parameters:
      user - The original username - ignored if null/empty
      Returns:
      The canonical user - unchanged if Unix O/S
    • resolveCanonicalGroup

      public static String resolveCanonicalGroup(String group, String user)
      Attempts to resolve canonical group name for Windows
      Parameters:
      group - The original group name - used if not null/empty
      user - The owner name - sometimes it contains a group name
      Returns:
      The canonical group name
    • setCurrentUser

      public static void setCurrentUser(String username)
      Can be used to programmatically set the username reported by getCurrentUser()
      Parameters:
      username - The username to set - if null then CURRENT_USER_OVERRIDE_PROP will be consulted
    • getJavaVersion

      public static VersionInfo getJavaVersion()
      Resolves the reported Java version by consulting JAVA_VERSION_OVERRIDE_PROP. If not set, then "java.version" property is used
      Returns:
      The resolved VersionInfo - never null
      See Also:
    • setJavaVersion

      public static void setJavaVersion(VersionInfo version)
      Set programmatically the reported Java version
      Parameters:
      version - The version - if null then it will be automatically resolved
    • getComparablePath

      public static String getComparablePath(String path)
      Parameters:
      path - The original path
      Returns:
      A path that can be compared with another one where case sensitivity of the underlying O/S has been taken into account - never null