FileSize implements Comparable<FileSize> { public FileSize(String string) { Pattern p = Pattern.compile("([\\d,.]+)\\s?([kKmMgGtT]{1})[Bb]{1}"); Matcher matcher = p.matcher(string); if (matcher.matches()) { double count = Double.parseDouble(matcher.group(1).replace(',','.')); long multiplier = 1; if (StringUtils.isNotBlank(matcher.group(2))) { multiplier = getMultiplier(matcher.group(2).charAt(0)); } bytes =(long)(count * multiplier); } } FileSize(String string);  FileSize(long bytes); long getBytes(); void setBytes(long bytes); @Override String toString(); long getMultiplier(char multiplierChar); static String convertToStringRepresentation(final long value); @Override int compareTo(FileSize o); @Override boolean equals(Object o); @Override int hashCode();  }
@Test (dataProvider = "testFileSizeDataProvider") public void testFileSize(String constructorArgs, long bytes) { Assert.assertEquals(new FileSize(constructorArgs).getBytes(), bytes); }