Top Description Fields Constructors Methods
org.apache.sshd.common.util

public final Class OsUtils

extends Object
Class Inheritance
Imports
java.nio.file.Path, .Paths, java.util.Arrays, .Collection, .Collections, .List, java.util.concurrent.atomic.AtomicReference, java.util.function.Predicate, .Supplier

Operating system dependent utility methods.
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
public static final List<String>
ANDROID_DETECTION_PROPERTIES

System properties consulted in order to detect Android O/S.

private static final AtomicReference<Boolean>
public static final String
ANDROID_MODE_OVERRIDE_PROP

Property that can be used to override the reported value from isAndroid().

public static final Predicate<String>
private static final AtomicReference<String>
public static final String
CURRENT_USER_OVERRIDE_PROP

Property that can be used to override the reported value from getCurrentUser().

private static final AtomicReference<Supplier<? extends Path>>
public static final List<String>
DALVIK_DETECTION_PROPERTIES

System properties consulted in order to detect Dalvik machine.

private static final AtomicReference<Boolean>
public static final String
DALVIK_MACHINE_OVERRIDE_PROP

Property that can be used to override the reported value from isDalvikMachine().

public static final Predicate<String>
private static final AtomicReference<VersionInfo>
public static final String
JAVA_VERSION_OVERRIDE_PROP

Property that can be used to override the reported value from getJavaVersion().

public static final List<String>
public static final String
private static final AtomicReference<String>
public static final String
OS_TYPE_OVERRIDE_PROP

Property that can be used to override the reported value from isWin32().

public static final String
public static final List<String>
public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

The canonical user - unchanged if Unix O/S
getCanonicalUser
(String
The original username - ignored if null/empty
user
)

Remove Windows domain and/or group prefix as well as "(User);" suffix

public static String

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
getComparablePath
(String
The original path
path
)

public static String

Returns:

Current user
getCurrentUser
()

Get current user name

public static Path

Returns:

The (C)urrent (W)orking (D)irectory Path - null if cannot resolve it. Resolution occurs as follows:
  • Consult any currently registered resolver.
  • If no resolver registered, then "user.dir" system property is consulted.
getCurrentWorkingDirectory
()

public static VersionInfo

Returns:

The resolved VersionInfo - never null
getJavaVersion
()

Resolves the reported Java version by consulting JAVA_VERSION_OVERRIDE_PROP.

private static String

Returns:

The resolved O/S type string if not already set (lowercase)
getOS
()

public static boolean

Returns:

true if currently running on Android. Note: isUNIX() is also probably true as well, so special care must be taken in code that consults these values
isAndroid
()

public static boolean

Returns:

true if currently running on a Dalvik machine. Note: isUNIX() and/or isAndroid() are also probably true as well, so special care must be taken in code that consults these values
isDalvikMachine
()

public static boolean

Returns:

true if the host is a OSX (and not Windows or Unix).
isOSX
()

public static boolean

Returns:

true if the host is a UNIX system (and not Windows). Note: this does not preclude isAndroid() or isDalvikMachine() from being true as well.
isUNIX
()

public static boolean

Returns:

true if the host is Windows (and not UNIX).
isWin32
()

private static boolean
resolveAndroidSettingFlag(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector)

public static String

Returns:

The canonical group name
resolveCanonicalGroup
(String
The original group name - used if not null/empty
group
,
String
The owner name - sometimes it contains a group name
user
)

Attempts to resolve canonical group name for Windows

public static List<String>
public static List<String>
public static String
public static String
public static void
setAndroid(Boolean
Value to set if null then value is auto-detected
value
)

Override the value returned by isAndroid() programmatically

public static void
setCurrentUser(String
The username to set - if null then CURRENT_USER_OVERRIDE_PROP will be consulted
username
)

Can be used to programmatically set the username reported by getCurrentUser()

public static void
setCurrentWorkingDirectoryResolver(Supplier<? extends Path>
The Supplier of the (C)urrent (W)orking (D)irectory Path - if null then "user.dir" system property is consulted
cwdProvider
)

Allows the user to "plug-in" a resolver for the getCurrentWorkingDirectory() method

public static void
setDalvikMachine(Boolean
Value to set if null then value is auto-detected
value
)

Override the value returned by isDalvikMachine() programmatically

public static void
setJavaVersion(VersionInfo
The version - if null then it will be automatically resolved
version
)

Set programmatically the reported Java version

public static void
setOS(String
The value to set - if null then O/S type is auto-detected
os
)

Can be used to enforce Win32 or Linux report from isWin32(), isOSX() or isUNIX()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANDROID_DETECTION_PROPERTIESback to summary
public static final List<String> ANDROID_DETECTION_PROPERTIES

System properties consulted in order to detect Android O/S.

See Also
Android Developer
ANDROID_HOLDERback to summary
private static final AtomicReference<Boolean> ANDROID_HOLDER
ANDROID_MODE_OVERRIDE_PROPback to summary
public static final String ANDROID_MODE_OVERRIDE_PROP

Property that can be used to override the reported value from isAndroid(). If not set then ANDROID_DETECTION_PROPERTIES are used to determine its value. Otherwise, it must contain the string "android" (case-insensitive)

See Also
ANDROID_PROPERTY_VALUE_MATCHER
ANDROID_PROPERTY_VALUE_MATCHERback to summary
public static final Predicate<String> ANDROID_PROPERTY_VALUE_MATCHER
CURRENT_USER_HOLDERback to summary
private static final AtomicReference<String> CURRENT_USER_HOLDER
CURRENT_USER_OVERRIDE_PROPback to summary
public static final String CURRENT_USER_OVERRIDE_PROP

Property that can be used to override the reported value from getCurrentUser(). If not set then "user.name" system property is used

CWD_PROVIDER_HOLDERback to summary
private static final AtomicReference<Supplier<? extends Path>> CWD_PROVIDER_HOLDER
DALVIK_DETECTION_PROPERTIESback to summary
public static final List<String> DALVIK_DETECTION_PROPERTIES

System properties consulted in order to detect Dalvik machine.

See Also
Android Developer
DALVIK_HOLDERback to summary
private static final AtomicReference<Boolean> DALVIK_HOLDER
DALVIK_MACHINE_OVERRIDE_PROPback to summary
public static final String DALVIK_MACHINE_OVERRIDE_PROP

Property that can be used to override the reported value from isDalvikMachine(). If not set then DALVIK_DETECTION_PROPERTIES are used to determine its value. Otherwise, it must contain the string "dalvik" (case-insensitive)

DALVIK_PROPERTY_VALUE_MATCHERback to summary
public static final Predicate<String> DALVIK_PROPERTY_VALUE_MATCHER
JAVA_VERSION_HOLDERback to summary
private static final AtomicReference<VersionInfo> JAVA_VERSION_HOLDER
JAVA_VERSION_OVERRIDE_PROPback to summary
public static final String JAVA_VERSION_OVERRIDE_PROP

Property that can be used to override the reported value from getJavaVersion(). If not set then "java.version" system property is used

LINUX_COMMANDback to summary
public static final List<String> LINUX_COMMAND
LINUX_SHELL_COMMAND_NAMEback to summary
public static final String LINUX_SHELL_COMMAND_NAME
OS_TYPE_HOLDERback to summary
private static final AtomicReference<String> OS_TYPE_HOLDER
OS_TYPE_OVERRIDE_PROPback to summary
public static final String OS_TYPE_OVERRIDE_PROP

Property that can be used to override the reported value from isWin32(). If not set then "os.name" system property is used

ROOT_USERback to summary
public static final String ROOT_USER
WINDOWS_COMMANDback to summary
public static final List<String> WINDOWS_COMMAND
WINDOWS_SHELL_COMMAND_NAMEback to summary
public static final String WINDOWS_SHELL_COMMAND_NAME

Constructor Detail

OsUtilsback to summary
private OsUtils()

Method Detail

getCanonicalUserback to summary
public static String getCanonicalUser(String user)

Remove Windows domain and/or group prefix as well as "(User);" suffix

Parameters
user:String

The original username - ignored if null/empty

Returns:String

The canonical user - unchanged if Unix O/S

getComparablePathback to summary
public static String getComparablePath(String path)
Parameters
path:String

The original path

Returns:String

A path that can be compared with another one where case sensitivity of the underlying O/S has been taken into account - never null

getCurrentUserback to summary
public static String getCurrentUser()

Get current user name

Returns:String

Current user

See Also
CURRENT_USER_OVERRIDE_PROP
getCurrentWorkingDirectoryback to summary
public static Path getCurrentWorkingDirectory()
Returns:Path

The (C)urrent (W)orking (D)irectory Path - null if cannot resolve it. Resolution occurs as follows:

  • Consult any currently registered resolver.
  • If no resolver registered, then "user.dir" system property is consulted.
See Also
setCurrentWorkingDirectoryResolver(Supplier)
getJavaVersionback to summary
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:VersionInfo

The resolved VersionInfo - never null

See Also
setJavaVersion(VersionInfo)
getOSback to summary
private static String getOS()
Returns:String

The resolved O/S type string if not already set (lowercase)

isAndroidback to summary
public static boolean isAndroid()
Returns:boolean

true if currently running on Android. Note: isUNIX() is also probably true as well, so special care must be taken in code that consults these values

See Also
ANDROID_DETECTION_PROPERTIES, ANDROID_MODE_OVERRIDE_PROP, ANDROID_PROPERTY_VALUE_MATCHER
isDalvikMachineback to summary
public static boolean isDalvikMachine()
Returns:boolean

true if currently running on a Dalvik machine. Note: isUNIX() and/or isAndroid() are also probably true as well, so special care must be taken in code that consults these values

See Also
DALVIK_DETECTION_PROPERTIES, DALVIK_MACHINE_OVERRIDE_PROP, DALVIK_PROPERTY_VALUE_MATCHER
isOSXback to summary
public static boolean isOSX()
Returns:boolean

true if the host is a OSX (and not Windows or Unix).

isUNIXback to summary
public static boolean isUNIX()
Returns:boolean

true if the host is a UNIX system (and not Windows). Note: this does not preclude isAndroid() or isDalvikMachine() from being true as well.

isWin32back to summary
public static boolean isWin32()
Returns:boolean

true if the host is Windows (and not UNIX).

See Also
OS_TYPE_OVERRIDE_PROP, setOS(String)
resolveAndroidSettingFlagback to summary
private static boolean resolveAndroidSettingFlag(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector)
resolveCanonicalGroupback to summary
public static String resolveCanonicalGroup(String group, String user)

Attempts to resolve canonical group name for Windows

Parameters
group:String

The original group name - used if not null/empty

user:String

The owner name - sometimes it contains a group name

Returns:String

The canonical group name

resolveDefaultInteractiveCommandElementsback to summary
public static List<String> resolveDefaultInteractiveCommandElements()
resolveDefaultInteractiveCommandElementsback to summary
public static List<String> resolveDefaultInteractiveCommandElements(boolean winOS)
resolveDefaultInteractiveShellCommandback to summary
public static String resolveDefaultInteractiveShellCommand()
resolveDefaultInteractiveShellCommandback to summary
public static String resolveDefaultInteractiveShellCommand(boolean winOS)
setAndroidback to summary
public static void setAndroid(Boolean value)

Override the value returned by isAndroid() programmatically

Parameters
value:Boolean

Value to set if null then value is auto-detected

setCurrentUserback to summary
public static void setCurrentUser(String username)

Can be used to programmatically set the username reported by getCurrentUser()

Parameters
username:String

The username to set - if null then CURRENT_USER_OVERRIDE_PROP will be consulted

setCurrentWorkingDirectoryResolverback to summary
public static void setCurrentWorkingDirectoryResolver(Supplier<? extends Path> cwdProvider)

Allows the user to "plug-in" a resolver for the getCurrentWorkingDirectory() method

Parameters
cwdProvider:Supplier<? extends Path>

The Supplier of the (C)urrent (W)orking (D)irectory Path - if null then "user.dir" system property is consulted

setDalvikMachineback to summary
public static void setDalvikMachine(Boolean value)

Override the value returned by isDalvikMachine() programmatically

Parameters
value:Boolean

Value to set if null then value is auto-detected

setJavaVersionback to summary
public static void setJavaVersion(VersionInfo version)

Set programmatically the reported Java version

Parameters
version:VersionInfo

The version - if null then it will be automatically resolved

setOSback to summary
public static void setOS(String os)

Can be used to enforce Win32 or Linux report from isWin32(), isOSX() or isUNIX()

Parameters
os:String

The value to set - if null then O/S type is auto-detected

See Also
isWin32(), isOSX(), isUNIX()