| java.lang.Object org.geotools.resources.Arguments
Arguments | public class Arguments (Code) | | A helper class for parsing command-line arguments. Instance of this class
are usually created inside
main methods. For example:
public static void main(String[] args) {
Arguments arguments = new Arguments(args);
}
Then, method likes
Arguments.getRequiredString or
Arguments.getOptionalString can be used.
If a parameter is badly formatted or if a required parameter is not presents, then the
method
Arguments.illegalArgument will be invoked with a message that describes the error.
The default implementation print the localized error message to standard output
Arguments.out and exits the virtual machine with a call to
System.exit with error code 1.
since: 2.0 version: $Id: Arguments.java 27848 2007-11-12 13:10:32Z desruisseaux $ author: Martin Desruisseaux |
Constructor Summary | |
public | Arguments(String[] args) Construct a console.
Parameters: args - Command line arguments. |
err | final public PrintWriter err(Code) | | Error stream to the console. This output stream will use
encoding specified in the "-encoding" argument, if
present. Otherwise, encoding will be fetch from user's
preference.
|
locale | final public Locale locale(Code) | | The locale. Locale will be fetch from the "-locale"
argument, if present. Otherwise, the default locale will be used.
|
out | final public PrintWriter out(Code) | | Output stream to the console. This output stream will use
encoding specified in the "-encoding" argument, if
present. Otherwise, encoding will be fetch from user's
preference.
|
Arguments | public Arguments(String[] args)(Code) | | Construct a console.
Parameters: args - Command line arguments. Arguments "-encoding" and "-locale" willbe automatically parsed. |
getFlag | public boolean getFlag(String name)(Code) | | Returns
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).
Parameters: name - The flag name. true if this flag appears on the command line, or false otherwise. |
getOptionalBoolean | public Boolean getOptionalBoolean(String name)(Code) | | Returns an optional boolean value from the command line.
The value, if defined, must be "true" or "false".
Parameters: name - The parameter name. Name are case-insensitive. The parameter value, of null if there is no parametergiven for the specified name. |
getOptionalDouble | public Double getOptionalDouble(String name)(Code) | | Returns an optional floating-point value from the command line. Numbers are parsed
as of the
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.
Parameters: name - The parameter name. Name are case-insensitive. The parameter value, of null if there is no parametergiven for the specified name. |
getOptionalInteger | public Integer getOptionalInteger(String name)(Code) | | Returns an optional integer value from the command line. Numbers are parsed as
of the
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.
Parameters: name - The parameter name. Name are case-insensitive. The parameter value, of null if there is no parametergiven for the specified name. |
getOptionalString | public String getOptionalString(String name)(Code) | | Returns an optional string value from the command line. This method should be called
exactly once for each parameter. Second invocation for the same parameter will returns
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.
Parameters: name - The parameter name (e.g. "-encoding"). Name are case-insensitive. The parameter value, of null if there is no parametergiven for the specified name. |
getPrintWriter | public static PrintWriter getPrintWriter(PrintStream out)(Code) | | Gets a print writer for the specified print stream. If the user specified an encoding
in some previous run of
Arguments , then this encoding will be used.
Parameters: out - The print stream to wrap. A PrintWriter wrapping the specified print stream with the user'sprefered encoding. |
getReader | public static Reader getReader(InputStream in)(Code) | | Gets a reader for the specified input stream. If the user specified an encoding
in some previous run of
Arguments , then this encoding will be used.
Parameters: in - The input stream to wrap. A Reader wrapping the specified input stream with the user'sprefered encoding. |
getRemainingArguments | public String[] getRemainingArguments(int max)(Code) | | Returns the list of unprocessed arguments. If the number of remaining arguments is
greater than the specified maximum, then this method invokes
Arguments.illegalArgument .
Parameters: max - Maximum remaining arguments autorized. An array of remaining arguments. Will never be longer than max . |
getRemainingArguments | public String[] getRemainingArguments(int max, char forbiddenPrefix)(Code) | | Returns the list of unprocessed arguments, which should not begin by the specified prefix. This
method invokes
(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.
Parameters: max - Maximum remaining arguments autorized. Parameters: forbiddenPrefix - The forbidden prefix, usually '-' . An array of remaining arguments. Will never be longer than max . since: 2.4 |
getRequiredBoolean | public boolean getRequiredBoolean(String name)(Code) | | Returns a required boolean value from the command line.
The value must be "true" or "false".
Parameters: name - The parameter name. Name are case-insensitive. The parameter value. |
getRequiredDouble | public double getRequiredDouble(String name)(Code) | | Returns a required floating-point value from the command line. Numbers are parsed
as of the
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.
Parameters: name - The parameter name. Name are case-insensitive. The parameter value. |
getRequiredInteger | public int getRequiredInteger(String name)(Code) | | Returns a required integer value from the command line. Numbers are parsed as
of the
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.
Parameters: name - The parameter name. Name are case-insensitive. The parameter value. |
getRequiredString | public String getRequiredString(String name)(Code) | | Returns an required string value from the command line. This method
works like
Arguments.getOptionalString , except that it will invokes
Arguments.illegalArgument if the specified parameter was not given
on the command line.
Parameters: name - The parameter name. Name are case-insensitive. The parameter value. |
getWriter | public static Writer getWriter(OutputStream out)(Code) | | Gets a writer for the specified output stream. If the user specified an encoding
in some previous run of
Arguments , then this encoding will be used.
Parameters: out - The output stream to wrap. A Writer wrapping the specified output stream with the user'sprefered encoding. |
illegalArgument | protected void illegalArgument(Exception exception)(Code) | | Invoked when an the user has specified an illegal parameter. The default
implementation prints the localized error message to the standard output
Arguments.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.
Parameters: exception - An exception with a message describing the user's error. |
printSummary | public void printSummary(Exception exception)(Code) | | Prints a summary of the specified exception, without stack trace. This method
is invoked when a non-fatal (and somewhat expected) error occured, for example
java.io.FileNotFoundException when the file were specified in argument.
Parameters: exception - An exception with a message describing the user's error. since: 2.3 |
|
|