|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcakoose.util.app.CommandLineLauncher
public abstract class CommandLineLauncher
A helper for writing command-line entrypoints. For example:
import blah.blah.CommandLineLauncher;
import blah.blah.CommandLineLauncher.Exit;
public class FileChanger extends CommandLineLauncher.TextOutput
{
// Your 'main' method should just relay to CommandLineLauncher.run(...), which
// will set things up and then call your 'run' method.
public static void main(String[] args)
{
CommandLineLauncher.run(new FileChanger(), args);
}
// Your 'run' method is now the program entrypoint.
public void run(PrintWriter out, InputStream in, PrintWriter err, String[] args)
throws Exit // 'throws' clause just for documentation purposes
{
// ...
}
}
Don't ever call System.exit(...). Instead, do:
if (somethingBadHappened) throw exit(5);
This allows 'finally' blocks to happen, which, among other things, allows the CommandLineLauncher to flush your stdout and stderr streams (otherwise, you'll be missing output).
| Nested Class Summary | |
|---|---|
static class |
CommandLineLauncher.Exit
|
static class |
CommandLineLauncher.RawOutput
|
static class |
CommandLineLauncher.TextOutput
|
| Method Summary | |
|---|---|
static void |
run(CommandLineLauncher.RawOutput launcher,
String[] args)
|
static void |
run(CommandLineLauncher.TextOutput launcher,
String[] args)
Equivalent to: run(launcher, args, true, true) |
static void |
run(CommandLineLauncher.TextOutput launcher,
String[] args,
boolean flushOut,
boolean flushErr)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void run(CommandLineLauncher.RawOutput launcher,
String[] args)
public static void run(CommandLineLauncher.TextOutput launcher,
String[] args,
boolean flushOut,
boolean flushErr)
args - The command-line arguments.flushOut - Whether the standard output stream should be set to autoflush.flushErr - Whether the standard output stream should be set to autoflush.PrintWriter autoflush
public static void run(CommandLineLauncher.TextOutput launcher,
String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||