@Test public void testParseFormattedSizeToBytesWithKiloByteStringAndNoB() { long expectedValue = 500000l; long valueReturn = FileUtils.parseFormattedSizeToBytes("500 KB"); assertEquals(expectedValue, valueReturn); }
public static long parseFormattedSizeToBytes(String humanReadableSize) { int identifier = -1; long value; int units_index = -1; while ( identifier == -1 && units_index < (units.length-1) ) { units_index++; identifier = humanReadableSize.toUpperCase().indexOf(units[units_index]); } if (identifier >= 0) { value = Long.parseLong(humanReadableSize.substring(0,identifier).trim()); boolean si = true; if( identifier == (humanReadableSize.length()-3) && humanReadableSize.charAt(identifier+1) == 'i' && humanReadableSize.charAt(identifier+2) == 'B' ) { si = false; } for (int i = 0; i <= units_index; i++) { value = value * (si ? 1000 : 1024); } } else { value = Long.parseLong(humanReadableSize.trim()); } return value; }
FileUtils extends org.apache.commons.io.FileUtils { public static long parseFormattedSizeToBytes(String humanReadableSize) { int identifier = -1; long value; int units_index = -1; while ( identifier == -1 && units_index < (units.length-1) ) { units_index++; identifier = humanReadableSize.toUpperCase().indexOf(units[units_index]); } if (identifier >= 0) { value = Long.parseLong(humanReadableSize.substring(0,identifier).trim()); boolean si = true; if( identifier == (humanReadableSize.length()-3) && humanReadableSize.charAt(identifier+1) == 'i' && humanReadableSize.charAt(identifier+2) == 'B' ) { si = false; } for (int i = 0; i <= units_index; i++) { value = value * (si ? 1000 : 1024); } } else { value = Long.parseLong(humanReadableSize.trim()); } return value; } }
FileUtils extends org.apache.commons.io.FileUtils { public static long parseFormattedSizeToBytes(String humanReadableSize) { int identifier = -1; long value; int units_index = -1; while ( identifier == -1 && units_index < (units.length-1) ) { units_index++; identifier = humanReadableSize.toUpperCase().indexOf(units[units_index]); } if (identifier >= 0) { value = Long.parseLong(humanReadableSize.substring(0,identifier).trim()); boolean si = true; if( identifier == (humanReadableSize.length()-3) && humanReadableSize.charAt(identifier+1) == 'i' && humanReadableSize.charAt(identifier+2) == 'B' ) { si = false; } for (int i = 0; i <= units_index; i++) { value = value * (si ? 1000 : 1024); } } else { value = Long.parseLong(humanReadableSize.trim()); } return value; }  }
FileUtils extends org.apache.commons.io.FileUtils { public static long parseFormattedSizeToBytes(String humanReadableSize) { int identifier = -1; long value; int units_index = -1; while ( identifier == -1 && units_index < (units.length-1) ) { units_index++; identifier = humanReadableSize.toUpperCase().indexOf(units[units_index]); } if (identifier >= 0) { value = Long.parseLong(humanReadableSize.substring(0,identifier).trim()); boolean si = true; if( identifier == (humanReadableSize.length()-3) && humanReadableSize.charAt(identifier+1) == 'i' && humanReadableSize.charAt(identifier+2) == 'B' ) { si = false; } for (int i = 0; i <= units_index; i++) { value = value * (si ? 1000 : 1024); } } else { value = Long.parseLong(humanReadableSize.trim()); } return value; }  static long parseFormattedSizeToBytes(String humanReadableSize); static String getGibibyteSizeStr(long size); }
FileUtils extends org.apache.commons.io.FileUtils { public static long parseFormattedSizeToBytes(String humanReadableSize) { int identifier = -1; long value; int units_index = -1; while ( identifier == -1 && units_index < (units.length-1) ) { units_index++; identifier = humanReadableSize.toUpperCase().indexOf(units[units_index]); } if (identifier >= 0) { value = Long.parseLong(humanReadableSize.substring(0,identifier).trim()); boolean si = true; if( identifier == (humanReadableSize.length()-3) && humanReadableSize.charAt(identifier+1) == 'i' && humanReadableSize.charAt(identifier+2) == 'B' ) { si = false; } for (int i = 0; i <= units_index; i++) { value = value * (si ? 1000 : 1024); } } else { value = Long.parseLong(humanReadableSize.trim()); } return value; }  static long parseFormattedSizeToBytes(String humanReadableSize); static String getGibibyteSizeStr(long size); static char[] units; }