|
GigaSpaces XAP 9.7.2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.jini.system.CommandLine com.sun.jini.system.MultiCommandLine
public class MultiCommandLine
This class parses a command line that uses multi-character options,
such as -verbose
or -help
.
To use MultiCommandLine
, create a MultiCommandLine
object with the array of strings you wish to parse (typically the
array passed to the utility's main
method), and then
consume options from it, providing default values in case the option
is not specified by the user. When you have consumed all the
options, you invoke the MultiCommandLine
object's
getOperands
method to return the remaining operands on
the command line. If ``--
'' is specified it is neither an
option nor an operand, just a separator between the two lists. The
CommandLine.BadInvocationException
is used to signal
errors in the construction of the strings, that is, a user error,
such as specifying a option that takes an argument but forgetting to
provide that argument. See the documentation for
MultiCommandLine.main
for an example.
You must call getOperands
for proper behavior, even if
you do not use any operands in your command. getOperands
checks for several user errors, including unknown options. If you
do not expect to use operands, you should check the return value of
getOperands
and complain if any are specified.
No options
can be consumed after getOperands
is invoked. Each
option may be used only once. Failure to follow these
rule is a programmer error that will result in a
CommandLine.ProgrammingException
.
MultiCommandLine
provides you several methods to get input
streams from the command line. If these do not suffice for your
particular needs, you can get the argument as a String
and do your own processing.
StringTokenizer
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.sun.jini.system.CommandLine |
---|
CommandLine.BadInvocationException, CommandLine.HelpOnlyException, CommandLine.ProgrammingException |
Constructor Summary | |
---|---|
MultiCommandLine(String[] args)
Create a new MultiCommandLine object that will
return specified options, arguments, and operands. |
|
MultiCommandLine(String prog,
String[] args)
Create a new MultiCommandLine object that will
return specified options, arguments, and operands. |
Method Summary | |
---|---|
boolean |
getBoolean(String opt)
Return true if the given option is specified on the
command line. |
double |
getDouble(String opt,
double defaultValue)
Return the value of the given double from the command line. |
InputStream |
getInputStream(String opt,
InputStream defaultValue)
Return a InputStream that is the result of creating a new
FileInputStream object for the file named by the given
option. |
InputStream |
getInputStream(String opt,
String path)
Return a InputStream that is the result of creating a new
FileInputStream object for the file named by the given
option. |
int |
getInt(String opt,
int defaultValue)
Return the argument of the given int option from
the command line. |
long |
getLong(String opt,
long defaultValue)
Return the argument of the given long option from
the command line. |
String[] |
getOperands()
Return the command line operands that come after the options. |
OutputStream |
getOutputStream(String opt,
OutputStream defaultValue)
Return a OutputStream that is the result of creating a new
FileOutputStream object for the file named by the given
option. |
OutputStream |
getOutputStream(String opt,
String path)
Return a InputStream that is the result of creating a new
FileInputStream object for the file named by the given
option. |
RandomAccessFile |
getRandomAccessFile(String opt,
RandomAccessFile defaultValue,
String mode)
Return a RandomAccessFile that is the result of
creating a new RandomAccessFile object for the file
named by the given option, using the given mode . |
RandomAccessFile |
getRandomAccessFile(String opt,
String path,
String mode)
Return a RandomAccessFile that is the result of
creating a new RandomAccessFile object for the file
named by the given option, using the given mode . |
Reader |
getReader(String opt,
Reader defaultValue)
Return a Reader that is the result of creating a new
FileReader object for the file named by the given
option. |
Reader |
getReader(String opt,
String path)
Return a Reader that is the result of creating a new
FileReader object for the file named by the given
option. |
String |
getString(String opt,
String defaultValue)
Return the argument of the given string option from the command line. |
Writer |
getWriter(String opt,
String path)
Return a Writer that is the result of creating a new
FileWriter object for the file named by the given
option. |
Writer |
getWriter(String opt,
Writer defaultValue)
Return a Writer that is the result of creating a new
FileWriter object for the file named by the given
option. |
void |
usage()
Print out a summary of the commands usage, inferred from the requested options. |
Methods inherited from class com.sun.jini.system.CommandLine |
---|
parseDouble, parseInputStream, parseInputStream, parseInt, parseLong, parseOutputStream, parseOutputStream, parseRandomAccessFile, parseRandomAccessFile, parseReader, parseReader, parseString, parseWriter, parseWriter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MultiCommandLine(String[] args)
MultiCommandLine
object that will
return specified options, arguments, and operands.
public MultiCommandLine(String prog, String[] args)
MultiCommandLine
object that will
return specified options, arguments, and operands. The
prog
parameter is the program name.
Method Detail |
---|
public boolean getBoolean(String opt)
true
if the given option is specified on the
command line.
public String getString(String opt, String defaultValue) throws CommandLine.BadInvocationException
defaultValue
.
CommandLine.BadInvocationException
public int getInt(String opt, int defaultValue) throws CommandLine.BadInvocationException, NumberFormatException
int
option from
the command line. If the option is not specified, return
defaultValue
.
CommandLine.BadInvocationException
NumberFormatException
CommandLine.parseInt(java.lang.String, int)
public long getLong(String opt, long defaultValue) throws CommandLine.BadInvocationException, NumberFormatException
long
option from
the command line. If the option is not specified, return
defaultValue
.
CommandLine.BadInvocationException
NumberFormatException
CommandLine.parseLong(java.lang.String, long)
public double getDouble(String opt, double defaultValue) throws CommandLine.BadInvocationException, NumberFormatException
double
from the command line.
If the option is not specified, return defaultValue
.
CommandLine.BadInvocationException
NumberFormatException
CommandLine.parseDouble(java.lang.String, double)
public Writer getWriter(String opt, Writer defaultValue) throws IOException, CommandLine.BadInvocationException
Writer
that is the result of creating a new
FileWriter
object for the file named by the given
option.
If the option is not specified, return defaultValue
.
IOException
CommandLine.BadInvocationException
CommandLine.parseWriter(java.lang.String,java.io.Writer)
public Writer getWriter(String opt, String path) throws IOException, CommandLine.BadInvocationException
Writer
that is the result of creating a new
FileWriter
object for the file named by the given
option.
If the option is not specified, the string path
is used
as the file name.
IOException
CommandLine.BadInvocationException
CommandLine.parseWriter(java.lang.String,java.lang.String)
public Reader getReader(String opt, Reader defaultValue) throws IOException, CommandLine.BadInvocationException
Reader
that is the result of creating a new
FileReader
object for the file named by the given
option.
If the option is not specified, return defaultValue
.
IOException
CommandLine.BadInvocationException
CommandLine.parseReader(java.lang.String,java.io.Reader)
public Reader getReader(String opt, String path) throws IOException, CommandLine.BadInvocationException
Reader
that is the result of creating a new
FileReader
object for the file named by the given
option.
If the option is not specified, the string path
is used
as the file name.
IOException
CommandLine.BadInvocationException
CommandLine.parseReader(java.lang.String,java.lang.String)
public OutputStream getOutputStream(String opt, OutputStream defaultValue) throws IOException, CommandLine.BadInvocationException
OutputStream
that is the result of creating a new
FileOutputStream
object for the file named by the given
option.
If the option is not specified, return defaultValue
.
IOException
CommandLine.BadInvocationException
CommandLine.parseOutputStream(java.lang.String,java.io.OutputStream)
public OutputStream getOutputStream(String opt, String path) throws IOException, CommandLine.BadInvocationException
InputStream
that is the result of creating a new
FileInputStream
object for the file named by the given
option.
If the option is not specified, the string path
is used
as the file name.
IOException
CommandLine.BadInvocationException
CommandLine.parseOutputStream(java.lang.String,java.lang.String)
public InputStream getInputStream(String opt, InputStream defaultValue) throws IOException, CommandLine.BadInvocationException
InputStream
that is the result of creating a new
FileInputStream
object for the file named by the given
option.
If the option is not specified, return defaultValue
.
IOException
CommandLine.BadInvocationException
CommandLine.parseInputStream(java.lang.String,java.io.InputStream)
public InputStream getInputStream(String opt, String path) throws IOException, CommandLine.BadInvocationException
InputStream
that is the result of creating a new
FileInputStream
object for the file named by the given
option.
If the option is not specified, the string path
is used
as the file name.
IOException
CommandLine.BadInvocationException
CommandLine.parseInputStream(java.lang.String,java.lang.String)
public RandomAccessFile getRandomAccessFile(String opt, RandomAccessFile defaultValue, String mode) throws IOException, CommandLine.BadInvocationException
RandomAccessFile
that is the result of
creating a new RandomAccessFile
object for the file
named by the given option, using the given mode
.
If the option is not specified, return defaultValue
.
IOException
CommandLine.BadInvocationException
CommandLine.parseRandomAccessFile(java.lang.String,java.io.RandomAccessFile,java.lang.String)
public RandomAccessFile getRandomAccessFile(String opt, String path, String mode) throws IOException, CommandLine.BadInvocationException
RandomAccessFile
that is the result of
creating a new RandomAccessFile
object for the file
named by the given option, using the given mode
.
If the option is not specified, the string path
is used
as the file name.
IOException
CommandLine.BadInvocationException
CommandLine.parseRandomAccessFile(java.lang.String,java.lang.String,java.lang.String)
public String[] getOperands() throws CommandLine.BadInvocationException, CommandLine.HelpOnlyException
This is also where -?
is handled. If the user
specifies -?
then the method usage
is
invoked and HelpOnlyException
is thrown. The
program is expected to catch this exception and simply exit
successfully.
CommandLine.BadInvocationException
CommandLine.HelpOnlyException
usage()
public void usage()
getOperands
has been (or is being) called. Adds ...
for
operands.
getOperands()
|
GigaSpaces XAP 9.7.2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |