GigaSpaces XAP 9.7.2 API

com.sun.jini.system
Class CommandLine

java.lang.Object
  extended by com.sun.jini.system.CommandLine
Direct Known Subclasses:
MultiCommandLine, POSIXCommandLine

public abstract class CommandLine
extends Object

CommandLine is a base class for command line parsing classes. It provides several useful methods for the implementor of the subclass and for the programmer. It also defines exceptions that can be generated during parsing commands.

CommandLine 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.

You can use these methods to parse your own operand arguments. For example, if your operands are integers, you may want to use parseInt to parse them to provide consistency to the user.

Author:
Sun Microsystems, Inc.
See Also:
POSIXCommandLine, MultiCommandLine

Nested Class Summary
static class CommandLine.BadInvocationException
          Signal that the user specified an option in an improper way.
static class CommandLine.HelpOnlyException
          Signal that this was a "help only" invocation.
static class CommandLine.ProgrammingException
          Signal that the programmer has invoked a method out of order.
 
Constructor Summary
CommandLine()
           
 
Method Summary
static double parseDouble(String str, double defaultValue)
          Return the result of parsing the given double from the command line.
static InputStream parseInputStream(String path, InputStream defaultValue)
          Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path.
static InputStream parseInputStream(String path, String defaultPath)
          Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path.
static int parseInt(String str, int defaultValue)
          Return the result of parsing the given int from the command line.
static long parseLong(String str, long defaultValue)
          Return the result of parsing the given long from the command line.
static OutputStream parseOutputStream(String path, OutputStream defaultValue)
          Return a OutputStream that is the result of creating a new FileOutputStream object for the file named by the given path.
static OutputStream parseOutputStream(String path, String defaultPath)
          Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path.
static RandomAccessFile parseRandomAccessFile(String path, RandomAccessFile defaultValue, String mode)
          Return a RandomAccessFile that is the result of creating a new RandomAccessFile object for the file named by the given path, using the given mode.
static RandomAccessFile parseRandomAccessFile(String path, String defaultPath, String mode)
          Return a RandomAccessFile that is the result of creating a new RandomAccessFile object for the file named by the given path, using the given mode.
static Reader parseReader(String path, Reader defaultValue)
          Return a Reader that is the result of creating a new FileReader object for the file named by the given path.
static Reader parseReader(String path, String defaultPath)
          Return a Reader that is the result of creating a new FileReader object for the file named by the given path.
static String parseString(String str, String defaultValue)
          Return the result of parsing the given string from the command line.
static Writer parseWriter(String path, String defaultPath)
          Return a Writer that is the result of creating a new FileWriter object for the file named by the given path.
static Writer parseWriter(String path, Writer defaultValue)
          Return a Writer that is the result of creating a new FileWriter object for the file named by the given path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine()
Method Detail

parseString

public static String parseString(String str,
                                 String defaultValue)
Return the result of parsing the given string from the command line. If str is null, return defaultValue.


parseInt

public static int parseInt(String str,
                           int defaultValue)
                    throws NumberFormatException
Return the result of parsing the given int from the command line. If str is null, return defaultValue. The value is parsed using to understand leading 0x or # to introduce a hexidecimal number, leading 0 to introduce an octal number, and anything else to be a decimal number.

Throws:
NumberFormatException

parseLong

public static long parseLong(String str,
                             long defaultValue)
                      throws NumberFormatException
Return the result of parsing the given long from the command line. If str is null, return defaultValue. The value is parsed using to understand leading 0x or # to introduce a hexidecimal number, leading 0 to introduce an octal number, and anything else to be a decimal number.

Throws:
NumberFormatException

parseDouble

public static double parseDouble(String str,
                                 double defaultValue)
                          throws NumberFormatException
Return the result of parsing the given double from the command line. If str is null, return defaultValue. The value is parsed using Double.value.

Throws:
NumberFormatException

parseWriter

public static Writer parseWriter(String path,
                                 Writer defaultValue)
                          throws IOException
Return a Writer that is the result of creating a new FileWriter object for the file named by the given path. If the argument is `-' then an OutputStreamWriter for System.out is returned. If path is null, return defaultValue.

Throws:
IOException

parseWriter

public static Writer parseWriter(String path,
                                 String defaultPath)
                          throws IOException
Return a Writer that is the result of creating a new FileWriter object for the file named by the given path. If the argument is `-' then an OutputStreamWriter for System.out is returned. If path is null, the string path is used as the file name.

Throws:
IOException

parseReader

public static Reader parseReader(String path,
                                 Reader defaultValue)
                          throws IOException
Return a Reader that is the result of creating a new FileReader object for the file named by the given path. If the argument is `-' then an InputStreamReader for System.in is returned. If path is null, return defaultValue.

Throws:
IOException

parseReader

public static Reader parseReader(String path,
                                 String defaultPath)
                          throws IOException
Return a Reader that is the result of creating a new FileReader object for the file named by the given path. If the argument is `-' then an InputStreamReader for System.in is returned. If path is null, the string path is used as the file name.

Throws:
IOException

parseOutputStream

public static OutputStream parseOutputStream(String path,
                                             OutputStream defaultValue)
                                      throws IOException
Return a OutputStream that is the result of creating a new FileOutputStream object for the file named by the given path. If the argument is `-' then System.out is returned. If path is null, return defaultValue.

Throws:
IOException

parseOutputStream

public static OutputStream parseOutputStream(String path,
                                             String defaultPath)
                                      throws IOException
Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path. If the argument is `-' then System.in is returned. If path is null, the string path is used as the file name.

Throws:
IOException

parseInputStream

public static InputStream parseInputStream(String path,
                                           InputStream defaultValue)
                                    throws IOException
Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path. If the argument is `-' then System.in is returned. If path is null, return defaultValue.

Throws:
IOException

parseInputStream

public static InputStream parseInputStream(String path,
                                           String defaultPath)
                                    throws IOException
Return a InputStream that is the result of creating a new FileInputStream object for the file named by the given path. If the argument is `-' then System.in is returned. If path is null, the string path is used as the file name.

Throws:
IOException

parseRandomAccessFile

public static RandomAccessFile parseRandomAccessFile(String path,
                                                     RandomAccessFile defaultValue,
                                                     String mode)
                                              throws IOException
Return a RandomAccessFile that is the result of creating a new RandomAccessFile object for the file named by the given path, using the given mode. If path is null, return defaultValue.

Throws:
IOException

parseRandomAccessFile

public static RandomAccessFile parseRandomAccessFile(String path,
                                                     String defaultPath,
                                                     String mode)
                                              throws IOException
Return a RandomAccessFile that is the result of creating a new RandomAccessFile object for the file named by the given path, using the given mode. If path is null, the string path is used as the file name.

Throws:
IOException

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.