Class SystemUtil


  • public class SystemUtil
    extends Object
    • Field Detail

      • TMP_DIR

        public static final String TMP_DIR
      • OS

        public static final OsType OS
      • OS_ARCH

        public static final OsArch OS_ARCH
      • OS_ARCH_TYPE

        public static final OsArchType OS_ARCH_TYPE
    • Constructor Detail

      • SystemUtil

        public SystemUtil()
    • Method Detail

      • setFilePermissions

        public static boolean setFilePermissions​(Path path,
                                                 PosixFilePermission... permissions)
        Sets silent file permissions (PosixFilePermissions will be mapped to filePermissions as windows doesn't understand posix)
        Parameters:
        path - Path to set permissions on
        permissions - permission list to set for the given Path
        Returns:
        true if no error occurred and if permissions are set successfully
      • copyResourceToTemp

        public static Path copyResourceToTemp​(Class<?> clazz,
                                              String relativePath)
        Copies a source file to temp path as the resources are not accessible/executable
        Parameters:
        clazz - Caller class to find its resource / get its classloader
        relativePath - relative resource file path
        Returns:
        temp path from copied file output
      • readFile

        public static String readFile​(Path path)
        Reads in a whole file
        Parameters:
        path - Filepath to read from
        Returns:
        File content
      • readFileLines

        public static List<String> readFileLines​(Path path)
        Reads in a whole file
        Parameters:
        path - Filepath to read from
        Returns:
        File content line wise
      • deleteDirectory

        public static boolean deleteDirectory​(Path path)
        Deletes silent a directory
        Parameters:
        path - directory to delete
        Returns:
        false on exception and any deletion error
      • killProcessByName

        public static void killProcessByName​(String name)
        kills processes by name
        Parameters:
        name - name of the process to kill