HumanReadableSize { public static String[] sanitize(final String size) { LOG.debug("Sanitizing '{}'", size); final Pattern patternClass = Pattern.compile("([0-9.]+)\\s*?([kMGTP]?B)"); final Matcher m = patternClass.matcher(size); String[] s = new String[]{size, "B"}; if (m.find()) { final String pureSize = m.group(1); final String sizeClass = m.group(2); s = new String[]{pureSize, sizeClass}; } if(LOG.isDebugEnabled()) { LOG.debug("Sanitized: {}", Arrays.deepToString(s)); } return s; } private  HumanReadableSize(); static String parse(final BigDecimal size); static String parse(final Long size); static String parse(final Integer size); static String parse(final String size); static String[] sanitize(final String size);  }
@Test public void sanitizeMegabytes() { assertArrayEquals(new String[]{"123456789", "MB"}, HumanReadableSize.sanitize("123456789MB")); }
@Test public void sanitizeGigabytes() { assertArrayEquals(new String[]{"123456789", "GB"}, HumanReadableSize.sanitize("123456789 GB")); }
@Test public void sanitizeKilTerabytes() { assertArrayEquals(new String[]{"123456789", "TB"}, HumanReadableSize.sanitize("123456789TB")); }
@Test public void sanitizeMissingSizeIndicator() { assertArrayEquals(new String[]{"123456789", "B"}, HumanReadableSize.sanitize("123456789")); }
@Test public void sanitizeBytes() { assertArrayEquals(new String[]{"123456789", "B"}, HumanReadableSize.sanitize("123456789 B")); }
@Test public void sanitizeKilobytes() { assertArrayEquals(new String[]{"123456789", "kB"}, HumanReadableSize.sanitize("123456789kB")); }