|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.Tools
public abstract class Tools
Constructor Summary | |
---|---|
Tools()
|
Method Summary | |
---|---|
static boolean |
bark(java.lang.String msg)
Displays an error message |
static java.lang.String |
commandLineArg(java.lang.String arg)
Wraps command line argument into quotes if it contains spaces |
static void |
fatalError(boolean condition,
java.lang.String message)
Reports a fatal error to sderr and exits, upon a condition |
static void |
fatalError(java.lang.Exception exception)
Reports a fatal exception to stderr and exits |
static void |
fatalError(java.lang.String message)
Reports a fatal error to sderr and exits |
static void |
fatalError(java.lang.String message,
java.lang.Exception exception)
Reports an error message and an exception to sderr and exits |
static java.lang.String |
freeMemory()
Collects garbage, reports back |
static java.lang.Long[] |
gc()
Collects garbage, reports back |
static java.lang.String |
getCommandOutput(java.lang.String command)
returns as string the output of a command |
static java.util.Map<java.lang.String,java.lang.String> |
getEnv()
gets values of all environment variables |
static boolean |
inform(java.lang.String msg)
Displays an informative message |
static boolean |
runCommand(java.lang.String cmd)
Runs a command in current directory |
static boolean |
runCommand(java.lang.String cmd,
java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err)
Runs a command in current directory |
static boolean |
runCommand(java.lang.String cmd,
java.io.PrintStream out,
java.io.PrintStream err)
Runs a command in current directory |
static boolean |
runCommand(java.lang.String cmd,
java.lang.String dir)
Runs a command in specified directory |
static boolean |
runCommand(java.lang.String cmd,
java.lang.String dir,
java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err)
Runs a command in specified directory |
static boolean |
runCommand(java.lang.String cmd,
java.lang.String dir,
java.io.PrintStream out,
java.io.PrintStream err)
Runs a command in specified directory |
static boolean |
runCommand(java.lang.String cmd,
java.lang.String dir,
java.io.Reader in,
java.io.PrintWriter out,
java.io.PrintWriter err)
Runs a command in specified directory |
static boolean |
runCommand(java.lang.String cmd,
java.lang.String dir,
java.io.Reader in,
java.io.PrintWriter out,
java.io.PrintWriter err,
java.util.Map<java.lang.String,java.lang.String> environment)
|
static int |
setLowestPriority()
sets the lowest priority, Thread.MIN_PRIORITY |
static int |
setPriority(int priority)
sets priority and returns previous priority |
static boolean |
whether(java.lang.String msg)
Displays a message and receives user's choice (yes/no) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Tools()
Method Detail |
---|
public static final void fatalError(boolean condition, java.lang.String message)
condition
- it is fatal error when condition is truemessage
- the error message
fatalError(!file.exists(), "File " + file + " does not exist!")
public static final void fatalError(java.lang.String message)
message
- the error message
fatalError("Your System is Windows!")
public static final void fatalError(java.lang.Exception exception)
exception
- the fatal exception
try {
prints
String s = null;
s.toString();
} catch (Exception e) {
fatalError(e);
}
java.lang.NullPointerException
at com.myjavatools.util.Tools.main
public static final void fatalError(java.lang.String message, java.lang.Exception exception)
message
- the error messageexception
- the fatal exception
try {
prints
String s = null;
s.toString();
} catch (Exception e) {
fatalError("Null pointers are bad!", e);
}
Null pointers are bad!
java.lang.NullPointerException
at com.myjavatools.util.Tools.main
public static boolean bark(java.lang.String msg)
msg
- the message to display
bark("Code Red Alert!")
.public static boolean inform(java.lang.String msg)
msg
- the message to display
inform("To beguile the time, be like the time.")
.public static boolean whether(java.lang.String msg)
msg
- the messge to display
if (!whether("Want this program to proceed?")) System.exit(1);
public static java.lang.Long[] gc()
public static java.lang.String freeMemory()
public static java.util.Map<java.lang.String,java.lang.String> getEnv()
public static boolean runCommand(java.lang.String cmd)
cmd
- the command to run; append '&' if no need to wait
runCommand("notepad&")> launches Notepad
runCommand("rmdir xxx")> returns false
(unless you had a directory 'xxx' and it was just removed).
public static boolean runCommand(java.lang.String cmd, java.lang.String dir)
cmd
- the command to run; append '&' if no need to waitdir
- starting directory name
runCommand("cmd /c dir .", "C:\\Program Files")>.
public static boolean runCommand(java.lang.String cmd, java.io.PrintStream out, java.io.PrintStream err)
cmd
- the command to run; append '&' if no need to waitout
- command output streamerr
- command error stream
runCommand("cmd /c dir .", "C:\\Program Files", System.out, System.err)>.
public static boolean runCommand(java.lang.String cmd, java.lang.String dir, java.io.PrintStream out, java.io.PrintStream err)
cmd
- the command to run; append '&' if no need to waitdir
- starting directory nameout
- command output streamerr
- command error stream
runCommand("cmd /c dir .", "C:\\Program Files", System.out, System.err)>.
public static boolean runCommand(java.lang.String cmd, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
cmd
- the command to run; append '&' if no need to waitin
- command input streamout
- command output streamerr
- command error stream
runCommand("cmd /c dir .", "C:\\Program Files", System.in, System.out, System.err)>.
public static boolean runCommand(java.lang.String cmd, java.lang.String dir, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
cmd
- the command to run; append '&' if no need to waitdir
- starting directory namein
- command input streamout
- command output streamerr
- command error stream
runCommand("cmd /c dir .", "C:\\Program Files", System.in, System.out, System.err)>.
public static boolean runCommand(java.lang.String cmd, java.lang.String dir, java.io.Reader in, java.io.PrintWriter out, java.io.PrintWriter err)
cmd
- the command to run; append '&' if no need to waitdir
- starting directory namein
- command input readerout
- command output writererr
- command error writer
runCommand("cmd /c dir .", "C:\\Program Files", System.in, System.out, System.err)>.
public static boolean runCommand(java.lang.String cmd, java.lang.String dir, java.io.Reader in, java.io.PrintWriter out, java.io.PrintWriter err, java.util.Map<java.lang.String,java.lang.String> environment)
public static java.lang.String getCommandOutput(java.lang.String command)
command
- String the command to run
public static java.lang.String commandLineArg(java.lang.String arg)
arg
-
public static int setPriority(int priority)
priority
- int
public static int setLowestPriority()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |