|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.martiansoftware.jsap.StringParser com.martiansoftware.jsap.stringparsers.LongSizeStringParser
A StringParser
that lets the user specify sizes with an optional unit.
This parser will parse its argument using parseSize(CharSequence)
.
IntSizeStringParser
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()
LongSizeStringParser
.
Convenient access to the only instance returned by
this method is available through
JSAP.LONGSIZE_PARSER
.
LongSizeStringParser
.public Object parse(String arg) throws ParseException
StringParser
parse
in class StringParser
arg
- the argument to convert to an Object of class appropriate to
the StringParser subclass.
ParseException
- if the specified argument cannot be parsed.public static long parseSize(CharSequence s) throws ParseException
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.
ParseException
- if s
is malformed, number is negative or
the resulting size is larger than Long.MAX_VALUE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |