public static long parseSize ( final String propertyName , final String propertyValue ) { final int lengthMinusSuffix = propertyValue . length ( ) - 1 ; final char lastCharacter = propertyValue . charAt ( lengthMinusSuffix ) ; if ( Character . isDigit ( lastCharacter ) ) { return Long . valueOf ( propertyValue ) ; } final long value = AsciiEncoding . parseLongAscii ( propertyValue , 0 , lengthMinusSuffix ) ; switch ( lastCharacter ) { case ' ' : case ' ' : if ( value > MAX_K_VALUE ) { throw new NumberFormatException ( propertyName + " would overflow long: " + propertyValue ) ; } return value * 1024 ; case ' ' : case ' ' : if ( value > MAX_M_VALUE ) { throw new NumberFormatException ( propertyName + " would overflow long: " + propertyValue ) ; } return value * 1024 * 1024 ; case ' ' : case ' ' : if ( value > MAX_G_VALUE ) { throw new NumberFormatException ( propertyName + " would overflow long: " + propertyValue ) ; } return value * 1024 * 1024 * 1024 ; default : throw new NumberFormatException ( propertyName + ": " + propertyValue + " should end with: k, m, or g." ) ; } }
Parse a string representation of a value with optional suffix of g m and k suffix to indicate gigabytes megabytes or kilobytes respectively .