Class SystemUtil


  • public class SystemUtil
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SystemUtil.OperatingSystem
      Supported operation system enum
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemUtil()  
    • Method Summary

      Modifier and Type Method Description
      static java.nio.file.Path copyResourceToTemp​(java.lang.Class clazz, java.lang.String relativePath)
      Copies a source file to temp path as the resources are not accessible/executable
      static boolean deleteDirectory​(java.nio.file.Path path)
      Deletes silent a directory
      static SystemUtil.OperatingSystem getOsType()
      Get current operating system
      static boolean isArm()
      Checks operating system with getOsType()
      static boolean isLinux()
      Checks operating system with getOsType()
      static boolean isMac()
      Checks operating system with getOsType()
      static boolean isSolaris()
      Checks operating system with getOsType()
      static boolean isUnknown()
      Checks operating system with getOsType()
      static boolean isWindows()
      Checks operating system with getOsType()
      static void killProcessByName​(java.lang.String name)
      kills processes by name
      static java.lang.String readFile​(java.nio.file.Path path)
      Reads in a whole file
      static java.util.List<java.lang.String> readFileLines​(java.nio.file.Path path)
      Reads in a whole file
      static boolean setFilePermissions​(java.nio.file.Path path, java.nio.file.attribute.PosixFilePermission... permissions)
      Sets silent file permissions (PosixFilePermissions will be mapped to filePermissions as windows doesn't understand posix)
      • Methods inherited from class java.lang.Object

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

      • SystemUtil

        public SystemUtil()
    • Method Detail

      • setFilePermissions

        public static boolean setFilePermissions​(java.nio.file.Path path,
                                                 java.nio.file.attribute.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 java.nio.file.Path copyResourceToTemp​(java.lang.Class clazz,
                                                            java.lang.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 java.lang.String readFile​(java.nio.file.Path path)
        Reads in a whole file
        Parameters:
        path - Filepath to read from
        Returns:
        File content
      • readFileLines

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

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

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