ConfigUtil { public static long getSizeBytes(String size) { Matcher matcher = NUMBER_AND_UNIT.matcher(size); if (matcher.matches()) { long number = Long.parseLong(matcher.group(1)); if (matcher.group(2) != null) { char unit = matcher.group(2).toLowerCase().charAt(0); switch (unit) { case 'b': return number; case 'k': return number * 1024; case 'm': return number * 1024 * 1024; case 'g': return number * 1024 * 1024 * 1024; default: throw new ConfigException("unknown size unit :" + unit); } } else { return number; } } else { throw new ConfigException("malformed size string: " + size); } }  static long getDurationMillis(String duration); static long getSizeBytes(String size);  }
@Test(groups = "fast") public void testSizeSanity() throws Exception { Assert.assertEquals(ConfigUtil.getSizeBytes("1001"), 1001); Assert.assertEquals(ConfigUtil.getSizeBytes("101b"), 101); Assert.assertEquals(ConfigUtil.getSizeBytes("10k"), 10240); Assert.assertEquals(ConfigUtil.getSizeBytes("101m"), 105906176); Assert.assertEquals(ConfigUtil.getSizeBytes("2g"), 2147483648L); }