Package berlin.yuna.clu.logic
Class SystemUtil
- java.lang.Object
-
- berlin.yuna.clu.logic.SystemUtil
-
public class SystemUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSystemUtil.OperatingSystemSupported operation system enum
-
Constructor Summary
Constructors Constructor Description SystemUtil()
-
Method Summary
Modifier and Type Method Description static java.nio.file.PathcopyResourceToTemp(java.lang.Class clazz, java.lang.String relativePath)Copies a source file to temp path as the resources are not accessible/executablestatic booleandeleteDirectory(java.nio.file.Path path)Deletes silent a directorystatic SystemUtil.OperatingSystemgetOsType()Get current operating systemstatic booleanisArm()Checks operating system withgetOsType()static booleanisLinux()Checks operating system withgetOsType()static booleanisMac()Checks operating system withgetOsType()static booleanisSolaris()Checks operating system withgetOsType()static booleanisUnknown()Checks operating system withgetOsType()static booleanisWindows()Checks operating system withgetOsType()static voidkillProcessByName(java.lang.String name)kills processes by namestatic java.lang.StringreadFile(java.nio.file.Path path)Reads in a whole filestatic java.util.List<java.lang.String>readFileLines(java.nio.file.Path path)Reads in a whole filestatic booleansetFilePermissions(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)
-
-
-
Method Detail
-
getOsType
public static SystemUtil.OperatingSystem getOsType()
Get current operating system- Returns:
- current
SystemUtil.OperatingSystemif supported, elseSystemUtil.OperatingSystem.UNKNOWN
-
isArm
public static boolean isArm()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.ARM
-
isLinux
public static boolean isLinux()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.LINUX
-
isMac
public static boolean isMac()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.MAC
-
isWindows
public static boolean isWindows()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.WINDOWS
-
isSolaris
public static boolean isSolaris()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.SOLARIS
-
isUnknown
public static boolean isUnknown()
Checks operating system withgetOsType()- Returns:
- true if the system is
SystemUtil.OperatingSystem.UNKNOWN
-
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 onpermissions- 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 classloaderrelativePath- 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
-
-