|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.resources.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. |
java.util.Locale |
locale
The locale. |
java.io.PrintWriter |
out
Output stream to the console. |
Constructor Summary | |
Arguments(java.lang.String[] args)
Construct a console. |
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.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. |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public final java.io.PrintWriter out
"-encoding" argument, if
present. Otherwise, encoding will be fetch from user's
preference.
public final java.io.PrintWriter err
"-encoding" argument, if
present. Otherwise, encoding will be fetch from user's
preference.
public final java.util.Locale locale
"-locale"
argument, if present. 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.
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)
Arguments
, then this encoding will be used.
in
- The input stream to wrap.
Reader
wrapping the specified input stream with the user's
prefered encoding.public static java.io.Writer getWriter(java.io.OutputStream out)
Arguments
, then this encoding will be used.
out
- The output stream to wrap.
Writer
wrapping the specified output stream with the user's
prefered encoding.public java.lang.String[] getRemainingArguments(int max)
illegalArgument(java.lang.Exception)
.
max
- Maximum remaining arguments autorized.
max
.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.
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 |