java.lang.Object
com.github.hypfvieh.util.SystemUtil
Utility-Class with various operating system related helper methods.
- Seit:
- v0.0.5 - 2015-08-05
- Autor:
- hypfvieh
-
Feldübersicht
Felder -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic StringappendSuffixIfMissing(String _str, String _suffix) Append a suffix to the string (e.g. filename) if it doesn't have it already.static StringappendTrailingDelimiter(String _filePath) Appends the OS specific path delimiter to the end of the String, if it is missing.static StringconcatFilePath(boolean _includeTrailingDelimiter, String... _parts) Concats a path from all given parts, using the path delimiter for the currently used platform.static StringconcatFilePath(String... _parts) Concats a path from all given parts, using the path delimiter for the currently used platform.static FilecreateTempDirectory(String _path, String _name, boolean _deleteOnExit) Creates a new temporary directory in the given path.static FilecreateTempDirectory(String _path, String _prefix, int _length, boolean _timestamp, boolean _deleteOnExit) Creates a temporary directory in the given path.static voiddeleteRecursively(String _fileOrDirectoryPath, boolean _stopOnError) Delete all files and directories in the given path recursively.static voiddeleteRecursivelyQuiet(String _fileOrDirectoryPath) Delete all files and directories in the given path recursively and without throwing any exception.static StringformatBytesHumanReadable(long _bytes, boolean _use1000BytesPerMb) Formats a file size given in byte to something human readable.static StringgetApplicationVersionFromJar(Class<?> _class, String _default) Read the JARs manifest and try to get the current program version from it.static StringDetermines the current logged on user.static StringgetFileExtension(File _file) Extracts the file extension (part behind last dot of a filename).static StringgetFileExtension(String _fileName) Extracts the file extension (part behind last dot of a filename).static FilegetFileIfReadable(String _file) Checks if given String is a valid file, e.g. file exists, is really a file and can be read.static StringGets the host name of the local machine.static StringDetermines the Java version of the executing JVM.static StringTries to get the current version of MacOS/MacOS X.static StringgetOs()Determines the operating system's type and version.static StringReturns the running class path.static StringReturns the temp directory of this platform.static StringReturns the current working directory.static StringTries to find the "default" terminal emulator.static booleanExamines some system properties to determine whether the process is likely being debugged in an IDE or remotely.static booleanisMacOs()Checks if the running OS is a MacOS/MacOS X.static StringnormalizePath(String _path) Normalize a file system path expression for the current OS.static StringnormalizePath(String _path, boolean _appendFinalSeparator) Normalize a file system path expression for the current OS.
-
Felddetails
-
FILE_SEPARATOR
Character that separates components of a file path. This is "/" on UNIX and "\" on Windows. -
LINE_SEPARATOR
Sequence used by operating system to separate lines in text files. -
TMP_DIR
The system's temporary-file directory.
-
-
Methodendetails
-
getOs
Determines the operating system's type and version.- Gibt zurück:
- the OS type and version as a string
-
getHostName
Gets the host name of the local machine.- Gibt zurück:
- host name
-
getWorkingDirectory
Returns the current working directory.- Gibt zurück:
- current working dir
-
getRunningClassPath
Returns the running class path.- Gibt zurück:
- String with classpath
-
getTempDir
Returns the temp directory of this platform.- Gibt zurück:
- temp directory
-
getJavaVersion
Determines the Java version of the executing JVM.- Gibt zurück:
- Java version
-
getCurrentUser
Determines the current logged on user.- Gibt zurück:
- logged on user
-
concatFilePath
Concats a path from all given parts, using the path delimiter for the currently used platform.- Parameter:
_includeTrailingDelimiter- include delimiter after last token_parts- parts to concat- Gibt zurück:
- concatinated string
-
concatFilePath
Concats a path from all given parts, using the path delimiter for the currently used platform. Does not include trailing delimiter.- Parameter:
_parts- parts to concat- Gibt zurück:
- concatinated string
-
appendSuffixIfMissing
Append a suffix to the string (e.g. filename) if it doesn't have it already.- Parameter:
_str- string to check_suffix- suffix to append- Gibt zurück:
- string with suffix or original if no suffix was appended
-
appendTrailingDelimiter
Appends the OS specific path delimiter to the end of the String, if it is missing.- Parameter:
_filePath- file path- Gibt zurück:
- String
-
createTempDirectory
Creates a new temporary directory in the given path.- Parameter:
_path- path_name- directory name_deleteOnExit- delete directory on jvm shutdown- Gibt zurück:
- created Directory, null if directory/file was already existing
-
createTempDirectory
public static File createTempDirectory(String _path, String _prefix, int _length, boolean _timestamp, boolean _deleteOnExit) Creates a temporary directory in the given path. You can specify certain files to get a random unique name.- Parameter:
_path- where to place the temp folder_prefix- prefix of the folder_length- length of random chars_timestamp- add timestamp (yyyyMMdd_HHmmss-SSS) to directory name_deleteOnExit- mark directory for deletion on jvm termination- Gibt zurück:
- file
-
isDebuggingEnabled
public static boolean isDebuggingEnabled()Examines some system properties to determine whether the process is likely being debugged in an IDE or remotely.- Gibt zurück:
- true if being debugged, false otherwise
-
getFileExtension
Extracts the file extension (part behind last dot of a filename). Only returns the extension, without the leading dot.- Parameter:
_fileName- filename- Gibt zurück:
- extension, empty string if no dot was found in filename or null if given String was null
-
getFileExtension
Extracts the file extension (part behind last dot of a filename). Only returns the extension, without the leading dot.- Parameter:
_file- file- Gibt zurück:
- extension, empty string if no dot was found in filename or null if given String was null
-
getFileIfReadable
Checks if given String is a valid file, e.g. file exists, is really a file and can be read. Throws IOException or Subclass of it, if file is either non-existing, not a file or unreadable.- Parameter:
_file- filename- Gibt zurück:
- file object, never null
- Löst aus:
IOException- if file could not be read
-
formatBytesHumanReadable
Formats a file size given in byte to something human readable.- Parameter:
_bytes- size in bytes_use1000BytesPerMb- use 1000 bytes per MByte instead of 1024- Gibt zurück:
- String
-
getApplicationVersionFromJar
Read the JARs manifest and try to get the current program version from it.- Parameter:
_class- class to use as entry point_default- default string to use if version could not be found- Gibt zurück:
- version or null
-
guessDefaultTerminal
Tries to find the "default" terminal emulator. This will be cmd.exe on windows and may vary on linux/unix systems depending on installed terminal programs. On linux/unix there is no generic way to find the default terminal, so all known terminal programs will be tried until any of them is found.- Gibt zurück:
- String with terminal name or null if terminal could not be determined
-
normalizePath
Normalize a file system path expression for the current OS. Replaces path separators by this OS's path separator. Appends a final path separator if parameter is set and if not yet present.- Parameter:
_path- path_appendFinalSeparator- controls appendix of separator at the end- Gibt zurück:
- normalized path
-
normalizePath
Normalize a file system path expression for the current OS. Replaces path separators by this OS's path separator. Appends a final path separator unless present.- Parameter:
_path- path- Gibt zurück:
- normalized path
-
isMacOs
public static boolean isMacOs()Checks if the running OS is a MacOS/MacOS X.- Gibt zurück:
- true if MacOS (or MacOS X), false otherwise
-
getMacOsMajorVersion
Tries to get the current version of MacOS/MacOS X. The version usually looks like '10.13.4', where the part behind the last dot represents the patchlevel. The major version in this case would be '10.13'.- Gibt zurück:
- version without patchlevel or null
-
deleteRecursively
public static void deleteRecursively(String _fileOrDirectoryPath, boolean _stopOnError) throws IOException Delete all files and directories in the given path recursively.- Parameter:
_fileOrDirectoryPath- path to delete_stopOnError- if true throw an exception and exit on any error- Löst aus:
IOException- if error occurs during deletion
-
deleteRecursivelyQuiet
Delete all files and directories in the given path recursively and without throwing any exception.- Parameter:
_fileOrDirectoryPath- file or directory to delete
-