public class OsUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EXEC_SUFFIX
Executable file suffix (nothing on UNIX, .exe on windows, etc.).
|
static int |
FILE_SEPARATOR_LENGTH
System file separator length.
|
private static boolean |
IS_WIN
Test if OS where this JDK is running windows.
|
static String |
LINES_SEPARATOR
System lines separator.
|
static String |
OS_NAME
OS name from system properties.
|
static String |
OS_NAME_PROPERTY
System property to retrieve OS name.
|
static String |
OS_NAME_UPCASE
OS name from system properties converted to upper case.
|
private static String |
OS_WIN_SUBSTR
Windows OS name substring used to identify Windows in OS name converted
to upper case.
|
Constructor and Description |
---|
OsUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
escapeParameters(String[] params)
Complementary method to parseParameters
|
static String |
escapeString(String s)
Escapes provided
String . |
static void |
escapeString(String s,
StringBuffer sb)
Escapes one string and appends it into provided
StringBuffer . |
static boolean |
isWin()
Check if OS where this JDK is running is windows.
|
static String |
joinPaths(String e1,
String e2)
Join 2 path elements separating them with path separator if not present
at the end of first path element.
|
static String[] |
parseParameters(String exec,
String args)
Parses parameters from a given string in shell-like manner and append
them to executable file.
|
static boolean |
rmDir(File target)
Recursive delete of directory structure.
|
static boolean |
rmDirContent(File target)
Recursive delete of internal files and directory structure.
|
public static final String LINES_SEPARATOR
public static final int FILE_SEPARATOR_LENGTH
public static final String OS_NAME_PROPERTY
public static final String OS_NAME
public static final String OS_NAME_UPCASE
private static final String OS_WIN_SUBSTR
private static final boolean IS_WIN
public static final String EXEC_SUFFIX
public static boolean isWin()
true
when this JDK is running on Windows
or false
otherwise.public static String[] parseParameters(String exec, String args)
c:\Program Files\jdk\bin\javac
.
Include extra command arguments, such as -Dname=value
.
Do anything else which might require unusual characters
or processing. For example:
"c:\program files\jdk\bin\java" -Dmessage="Hello /\\/\\ there!" -Xmx128m
This example would create the following executable name and
arguments:
c:\program files\jdk\bin\java
-Dmessage=Hello /\/\ there!
-Xmx128m
args
- A String to parsepublic static String escapeParameters(String[] params)
public static void escapeString(String s, StringBuffer sb)
StringBuffer
.
s
- String to be escaped.sb
- Target StringBuffer
.escapeParameters(java.lang.String[])
public static boolean rmDirContent(File target)
target
- File or directory which content will be deleted.public static boolean rmDir(File target)
target
- File or directory to be deleted.Copyright © 2013. All Rights Reserved.