code: public static long parseSize(String s) {
          Matcher m = p_mem.matcher(s);
          if (m.find()) {
              long i = Long.parseLong(m.group(1));
              char multiplier = 'B';
              if (m.group(2) != null && m.group(2).length() == 1) {
                  multiplier = m.group(2).charAt(0);
              }
              if (multiplier == 'B') {
                  return (long) i;
              }
              if (multiplier == 'K') {
                  return (long) i * 1024l;
              }
              if (multiplier == 'M') {
                  return (long) i * 1024l * 1024l;
              }
              if (multiplier == 'G') {
                  return (long) i * 1024l * 1024l * 1024l;
              }
          }
          return -1;
      }
docs: This methods parses the given String, which should represent a size, to a long. 'K' is interpreted as 1024, 'M'
  as 1024^2 and 'G' as 1024^3.
  
  @param s
  the String to parse
  @return size in byte. -1 if the String was not parsable.