public final class SystemUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
FILE_SEPARATOR
Character that separates components of a file path.
|
static String |
LINE_SEPARATOR
Sequence used by operating system to separate lines in text files.
|
static String |
TMP_DIR
The system's temporary-file directory.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
appendSuffixIfMissing(String _str,
String _suffix)
Append a suffix to the string (e.g. filename) if it doesn't have it already.
|
static String |
appendTrailingDelimiter(String _filePath)
Appends the OS specific path delimiter to the end of the String, if it is missing.
|
static String |
concatFilePath(boolean _includeTrailingDelimiter,
String... _parts)
Concats a path from all given parts, using the path delimiter for the currently used platform.
|
static String |
concatFilePath(String... _parts)
Concats a path from all given parts, using the path delimiter for the currently used platform.
|
static File |
createTempDirectory(String _path,
String _name,
boolean _deleteOnExit)
Creates a new temporary directory in the given path.
|
static File |
createTempDirectory(String _path,
String _prefix,
int _length,
boolean _timestamp,
boolean _deleteOnExit)
Creates a temporary directory in the given path.
|
static String |
formatBytesHumanReadable(long _bytes,
boolean _use1000BytesPerMb)
Formats a file size given in byte to something human readable.
|
static String |
getApplicationVersionFromJar(Class<?> _class,
String _default)
Read the JARs manifest and try to get the current program version from it.
|
static String |
getCurrentUser()
Determines the current logged on user.
|
static String |
getFileExtension(File _file)
Extracts the file extension (part behind last dot of a filename).
|
static String |
getFileExtension(String _fileName)
Extracts the file extension (part behind last dot of a filename).
|
static File |
getFileIfReadable(String _file)
Checks if given String is a valid file, e.g. file exists, is really a file and can be read.
|
static String |
getHostName()
Gets the host name of the local machine.
|
static String |
getJavaVersion()
Determines the Java version of the executing JVM.
|
static String |
getOs()
Determines the operating system's type and version.
|
static String |
getRunningClassPath()
Returns the running class path.
|
static String |
getTempDir()
Returns the temp directory of this platform.
|
static String |
getWorkingDirectory()
Returns the current working directory.
|
static String |
guessDefaultTerminal()
Tries to find the "default" terminal emulator.
|
static boolean |
isDebuggingEnabled()
Examines some system properties to determine whether the process is likely being debugged
in an IDE or remotely.
|
static String |
normalizePath(String _path)
Normalize a file system path expression for the current OS.
|
static String |
normalizePath(String _path,
boolean _appendFinalSeparator)
Normalize a file system path expression for the current OS.
|
public static final String FILE_SEPARATOR
public static final String LINE_SEPARATOR
public static final String TMP_DIR
public static String getOs()
public static String getHostName()
public static String getWorkingDirectory()
public static String getRunningClassPath()
public static String getTempDir()
public static String getJavaVersion()
public static String getCurrentUser()
public static String concatFilePath(boolean _includeTrailingDelimiter, String... _parts)
_includeTrailingDelimiter - include delimiter after last token_parts - parts to concatpublic static String concatFilePath(String... _parts)
_parts - parts to concatpublic static String appendSuffixIfMissing(String _str, String _suffix)
_str - string to check_suffix - suffix to appendpublic static String appendTrailingDelimiter(String _filePath)
_filePath - file pathpublic static File createTempDirectory(String _path, String _name, boolean _deleteOnExit)
_path - path_name - directory name_deleteOnExit - delete directory on jvm shutdownpublic static File createTempDirectory(String _path, String _prefix, int _length, boolean _timestamp, boolean _deleteOnExit)
_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 terminationpublic static boolean isDebuggingEnabled()
public static String getFileExtension(String _fileName)
_fileName - filenamepublic static String getFileExtension(File _file)
_file - filepublic static File getFileIfReadable(String _file) throws IOException
_file - filenameIOException - if file could not be readpublic static String formatBytesHumanReadable(long _bytes, boolean _use1000BytesPerMb)
_bytes - size in bytes_use1000BytesPerMb - use 1000 bytes per MByte instead of 1024public static String getApplicationVersionFromJar(Class<?> _class, String _default)
_class - class to use as entry point_default - default string to use if version could not be foundpublic static String guessDefaultTerminal()
public static String normalizePath(String _path, boolean _appendFinalSeparator)
_path - path_appendFinalSeparator - controls appendix of separator at the endCopyright © 2018. All rights reserved.