|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.resources.Arguments
public class Arguments
A helper class for parsing command-line arguments. Instance of this class
are usually created inside main
methods. For example:
Then, method likespublic static void main(String[] args) { Arguments arguments = new Arguments(args); }
getRequiredString(java.lang.String)
or getOptionalString(java.lang.String)
can be used.
If a parameter is badly formatted or if a required parameter is not presents, then the
method illegalArgument(java.lang.Exception)
will be invoked with a message that describes the error.
The default implementation print the localized error message to standard output out
and exits the virtual machine with a call to System.exit(int)
with error code 1.
Field Summary | |
---|---|
java.io.PrintWriter |
err
Error stream to the console. |
static int |
ILLEGAL_ARGUMENT_EXIT_CODE
Deprecated. Moved to CommandLine . |
java.util.Locale |
locale
The locale. |
java.io.PrintWriter |
out
Output stream to the console. |
Constructor Summary | |
---|---|
Arguments(java.lang.String[] args)
Constructs a set of arguments. |
Method Summary | |
---|---|
boolean |
getFlag(java.lang.String name)
Returns true if the specified flag is set on the command line. |
java.lang.Boolean |
getOptionalBoolean(java.lang.String name)
Returns an optional boolean value from the command line. |
java.lang.Double |
getOptionalDouble(java.lang.String name)
Returns an optional floating-point value from the command line. |
java.lang.Integer |
getOptionalInteger(java.lang.String name)
Returns an optional integer value from the command line. |
java.lang.String |
getOptionalString(java.lang.String name)
Returns an optional string value from the command line. |
static java.io.PrintWriter |
getPrintWriter(java.io.PrintStream out)
Gets a print writer for the specified print stream. |
static java.io.Reader |
getReader(java.io.InputStream in)
Gets a reader for the specified input stream. |
java.lang.String[] |
getRemainingArguments(int max)
Returns the list of unprocessed arguments. |
java.lang.String[] |
getRemainingArguments(int max,
char forbiddenPrefix)
Returns the list of unprocessed arguments, which should not begin by the specified prefix. |
boolean |
getRequiredBoolean(java.lang.String name)
Returns a required boolean value from the command line. |
double |
getRequiredDouble(java.lang.String name)
Returns a required floating-point value from the command line. |
int |
getRequiredInteger(java.lang.String name)
Returns a required integer value from the command line. |
java.lang.String |
getRequiredString(java.lang.String name)
Returns an required string value from the command line. |
static java.io.Writer |
getWriter(java.io.OutputStream out)
Gets a writer for the specified output stream. |
protected void |
illegalArgument(java.lang.Exception exception)
Invoked when an the user has specified an illegal parameter. |
void |
printSummary(java.lang.Exception exception)
Prints a summary of the specified exception, without stack trace. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@Deprecated public static final int ILLEGAL_ARGUMENT_EXIT_CODE
CommandLine
.System.exit(int)
when this class exits because of an illegal
user argument.
public final java.io.PrintWriter out
"-encoding"
argument, if presents.
public final java.io.PrintWriter err
public final java.util.Locale locale
"-locale"
argument, if presents. Otherwise, the default locale will be used.
Constructor Detail |
---|
public Arguments(java.lang.String[] args)
args
- Command line arguments. Arguments "-encoding"
and "-locale"
will be automatically parsed.Method Detail |
---|
public java.lang.String getOptionalString(java.lang.String name)
null
, unless the same parameter appears many times on the command line.
Paramater may be instructions like "-encoding cp850" or "-encoding=cp850". Both forms (with or without "=") are accepted. Spaces around the '=' character, if any, are ignored.
name
- The parameter name (e.g. "-encoding"). Name are case-insensitive.
null
if there is no parameter
given for the specified name.public java.lang.String getRequiredString(java.lang.String name)
getOptionalString(java.lang.String)
, except that it will invokes
illegalArgument(java.lang.Exception)
if the specified parameter was not given
on the command line.
name
- The parameter name. Name are case-insensitive.
public java.lang.Integer getOptionalInteger(java.lang.String name)
Integer.parseInt(String)
method, which means that the parsing
is locale-insensitive. Locale insensitive parsing is required in order to use
arguments in portable scripts.
name
- The parameter name. Name are case-insensitive.
null
if there is no parameter
given for the specified name.public int getRequiredInteger(java.lang.String name)
Integer.parseInt(String)
method, which means that the parsing
is locale-insensitive. Locale insensitive parsing is required in order to use
arguments in portable scripts.
name
- The parameter name. Name are case-insensitive.
public java.lang.Double getOptionalDouble(java.lang.String name)
Double.parseDouble(String)
method, which means that the parsing
is locale-insensitive. Locale insensitive parsing is required in order to use
arguments in portable scripts.
name
- The parameter name. Name are case-insensitive.
null
if there is no parameter
given for the specified name.public double getRequiredDouble(java.lang.String name)
Double.parseDouble(String)
method, which means that the parsing
is locale-insensitive. Locale insensitive parsing is required in order to use
arguments in portable scripts.
name
- The parameter name. Name are case-insensitive.
public java.lang.Boolean getOptionalBoolean(java.lang.String name)
name
- The parameter name. Name are case-insensitive.
null
if there is no parameter
given for the specified name.public boolean getRequiredBoolean(java.lang.String name)
name
- The parameter name. Name are case-insensitive.
public boolean getFlag(java.lang.String name)
true
if the specified flag is set on the command line.
This method should be called exactly once for each flag. Second invocation
for the same flag will returns false
(unless the same flag
appears many times on the command line).
name
- The flag name.
true
if this flag appears on the command line, or false
otherwise.public static java.io.Reader getReader(java.io.InputStream in)
in
- The input stream to wrap.
Reader
wrapping the specified input stream.public static java.io.Writer getWriter(java.io.OutputStream out)
out
- The output stream to wrap.
Writer
wrapping the specified output stream.public static java.io.PrintWriter getPrintWriter(java.io.PrintStream out)
out
- The print stream to wrap.
PrintWriter
wrapping the specified print stream.public java.lang.String[] getRemainingArguments(int max)
illegalArgument(java.lang.Exception)
.
max
- Maximum remaining arguments autorized.
max
.public java.lang.String[] getRemainingArguments(int max, char forbiddenPrefix)
getRemainingArguments(max)
and verifies that none of the remaining arguments start with forbiddenPrefix
. The
forbidden prefix is usually '-'
, the character used for options as in
"-locale
", etc.
max
- Maximum remaining arguments autorized.forbiddenPrefix
- The forbidden prefix, usually '-'
.
max
.public void printSummary(java.lang.Exception exception)
FileNotFoundException
when the file were specified in argument.
exception
- An exception with a message describing the user's error.protected void illegalArgument(java.lang.Exception exception)
out
, and then exit the virtual machine. User may override this
method if they want a different behavior.
This method is not invoked when an anormal error occured (for
example an unexpected NullPointerException
in some of developper's
module). If such an error occurs, the normal exception mechanism will be used.
exception
- An exception with a message describing the user's error.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |