Class User


  • public class User
    extends Object
    Class for returning information about the current user.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • ADAMS_USERNAME

        public static final String ADAMS_USERNAME
        environment variable for overriding the user name (user.name).
        See Also:
        Constant Field Values
      • ADAMS_USERHOME

        public static final String ADAMS_USERHOME
        environment variable for overriding the user home dir (user.home).
        See Also:
        Constant Field Values
      • ADAMS_USERDIR

        public static final String ADAMS_USERDIR
        environment variable for overriding the current working dir (user.dir).
        See Also:
        Constant Field Values
      • m_UserName

        protected static String m_UserName
        the user name.
      • m_UserHome

        protected static String m_UserHome
        the user home.
      • m_UserDir

        protected static String m_UserDir
        the user dir (CWD).
      • m_UserID

        protected static Integer m_UserID
        the user ID.
      • m_GroupID

        protected static Integer m_GroupID
        the user's group ID.
    • Constructor Detail

      • User

        public User()
    • Method Detail

      • getHomeDir

        public static String getHomeDir()
        Returns the user's home directory. Can be overridden with ADAMS_USERHOME environment variable.
        Returns:
        the directory
        See Also:
        ADAMS_USERHOME
      • getCWD

        public static String getCWD()
        Returns the user's current working directory. Can be overridden with ADAMS_USERDIR environment variable.
        Returns:
        the directory
        See Also:
        ADAMS_USERDIR
      • cmdOutput

        protected static String cmdOutput​(String[] cmd,
                                          String defValue)
        Runs the specified command and returns the output from stdout.
        Parameters:
        cmd - the command to run
        defValue - the default output
        Returns:
        the generated output or default value if failed to execute
      • getUserID

        public static int getUserID()
        Returns the user's ID for *nix-like systems (id -u).
        Returns:
        the user ID, -1 if not available
      • getGroupID

        public static int getGroupID()
        Returns the user's group ID for *nix-like systems (id -g).
        Returns:
        the group ID, -1 if not available