KubernetesSize { public static long toBytes(String sizeString) { final Matcher matcher; if ((matcher = HUMAN_SIZE_MEMORY_PATTERN.matcher(sizeString)).matches()) { final float size = Float.parseFloat(matcher.group(1)); final String suffix = matcher.group(3); if (suffix == null) { return (long) size; } switch (suffix.toLowerCase()) { case "b": case "bi": return (long) size; case "k": return (long) (size * K); case "ki": case "kib": return (long) (size * KI); case "m": return (long) (size * M); case "mi": case "mib": return (long) (size * MI); case "g": return (long) (size * G); case "gi": case "gib": return (long) (size * GI); case "t": return (long) (size * T); case "ti": case "tib": return (long) (size * TI); case "p": return (long) (size * P); case "pi": case "pib": return (long) (size * PI); case "e": return (long) (size * E); case "ei": case "eib": return (long) (size * EI); } } throw new IllegalArgumentException("Invalid Kubernetes size format provided: " + sizeString); }  static long toBytes(String sizeString); static String toKubeSize(long bytes, boolean si); static float toCores(String cpuString);  }
@Test(dataProvider = "validSizes") public void testParseKubernetesMemoryFormatsToBytes(String kubeSize, long expectedBytes) throws Exception { assertEquals(KubernetesSize.toBytes(kubeSize), expectedBytes); }