* the resulting size is larger than {@link Long#MAX_VALUE}.
*/
public static long parseSize( final CharSequence s ) throws ParseException {
final Matcher m = PARSE_SIZE_REGEX.matcher( s );
if ( ! m.matches() ) throw new ParseException( "Invalid size specification '" + s + "'." );
final String unit = m.group( 3 );
BigInteger unitSize = BigInteger.ONE;
if ( unit != null ) {
Long unitSizeObj = (Long)UNIT2SIZE.get( unit );
if ( unitSizeObj == null ) throw new ParseException( "Invalid unit specification '" + unit + "'." );
unitSize = new BigInteger( unitSizeObj.toString() );
}
final String number = m.group( 1 );
final Long size;
try {
size = Long.decode( number );
if ( size.longValue() < 0 ) throw new ParseException( "Sizes cannot be negative." );
}
catch( NumberFormatException e ) {
throw new ParseException( "Invalid number '" + number + "'." );
}
BigInteger result = new BigInteger( size.toString() ).multiply( unitSize );
if ( result.compareTo( LONG_MAX_VALUE ) > 0 ) throw new ParseException( "Size '" + s + "' is too big." );
return Long.parseLong( result.toString() );
}