private static long humanReadableSizeToBytes(final String humanReadableSize)
    throws HBaseException {
    if (humanReadableSize == null) {
      return -1;
    }

    try {
      return Long.parseLong(humanReadableSize);
    } catch (NumberFormatException ex) {
      LOG.debug("Given size value is not a number, parsing for human readable format");
    }

    String tb = null;
    String gb = null;
    String mb = null;
    String kb = null;
    String b = null;
    String expectedSize = null;
    long size = 0;

    Matcher matcher = PrettyPrinter.SIZE_PATTERN.matcher(humanReadableSize);
    if (matcher.matches()) {
      expectedSize = matcher.group(2);
      tb = matcher.group(4);
      gb = matcher.group(6);
      mb = matcher.group(8);
      kb = matcher.group(10);
      b = matcher.group(12);
    }
    size += tb != null ? Long.parseLong(tb) * HConstants.TB_IN_BYTES : 0;
    size += gb != null ? Long.parseLong(gb) * HConstants.GB_IN_BYTES : 0;
    size += mb != null ? Long.parseLong(mb) * HConstants.MB_IN_BYTES : 0;
    size += kb != null ? Long.parseLong(kb) * HConstants.KB_IN_BYTES : 0;
    size += b != null ? Long.parseLong(b) : 0;

    if (expectedSize != null && Long.parseLong(expectedSize) != size) {
      throw new HBaseException(
        "Malformed size string: values in byte and human readable" + "format do not match");
    }
    return size;
  }
Convert a human readable size to bytes. Examples of the human readable size are: 50 GB 20 MB 1
KB , 25000 B etc. The units of size specified can be in uppercase as well as lowercase. Also,
if a single number is specified without any time unit, it is assumed to be in bytes.
@param humanReadableSize human readable size
@return value in bytes
hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java