Class LongSizeStringParser

  extended bycom.martiansoftware.jsap.StringParser
      extended bycom.martiansoftware.jsap.stringparsers.LongSizeStringParser

public class LongSizeStringParser
extends StringParser

A StringParser that lets the user specify sizes with an optional unit.

This parser will parse its argument using parseSize(CharSequence).

Sebastiano Vigna
See Also:

Method Summary
static LongSizeStringParser getParser()
          Returns the only instance of a LongSizeStringParser.
 Object parse(String arg)
          Parses the specified argument into an Object of the appropriate type.
static long parseSize(CharSequence s)
          Parses a size specified using units (e.g., K, Ki, M, Mi,…).
Methods inherited from class com.martiansoftware.jsap.StringParser
setUp, tearDown
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static LongSizeStringParser getParser()
Returns the only instance of a LongSizeStringParser.

Convenient access to the only instance returned by this method is available through JSAP.LONGSIZE_PARSER.

the only instance of a LongSizeStringParser.


public Object parse(String arg)
             throws ParseException
Description copied from class: StringParser
Parses the specified argument into an Object of the appropriate type. If the specified argument cannot be converted into the desired Object, a ParseException should be thrown.

Note: this method MAY BE CALLED with a null argument. Take this into consideration when subclassing!

Specified by:
parse in class StringParser
arg - the argument to convert to an Object of class appropriate to the StringParser subclass.
the Object resulting from the parsed argument.
ParseException - if the specified argument cannot be parsed.


public static long parseSize(CharSequence s)
                      throws ParseException
Parses a size specified using units (e.g., K, Ki, M, Mi,…).

The argument must be in the form number [unit] (with no space inbetween). number is anything accepted by Long.decode(java.lang.String), which allows, besides decimal numbers, hexadecimal numbers prefixed by 0x, 0X or #, and octal numbers prefixed by 0. unit may be one of K (103), Ki (210), M (106), Mi (220), G (109), Gi (230), T (1012), Ti (240), P (1015), Pi (250). Thus, for instance, 1Ki is 1024, whereas 9M is nine millions and 0x10Pi is 18014398509481984. Note that in the number part case does not matter, but in the unit part it does.

s - a size specified as above.
the corresponding unitless size.
ParseException - if s is malformed, number is negative or the resulting size is larger than Long.MAX_VALUE.

Copyright © 2002-2006, Martian Software, Inc.. All Rights Reserved.
For the latest version and documentation, please visit