MCPcopy
hub / github.com/oshi/oshi / formatBytes

Method formatBytes

oshi-core/src/main/java/oshi/util/FormatUtil.java:82–100  ·  view source on GitHub ↗

Format bytes into a rounded string representation using IEC standard (matches Mac/Linux). For hard drive capacities, use @link #formatBytesDecimal(long). For Windows displays for KB, MB and GB, in JEDEC units, edit the returned string to remove the 'i' to display the (incorrect) JEDEC units.

(long bytes)

Source from the content-addressed store, hash-verified

80 * @return Rounded string representation of the byte size.
81 */
82 public static String formatBytes(long bytes) {
83 if (bytes == 1L) { // bytes
84 return String.format("%d byte", bytes);
85 } else if (bytes < KIBI) { // bytes
86 return String.format("%d bytes", bytes);
87 } else if (bytes < MEBI) { // KiB
88 return formatUnits(bytes, KIBI, "KiB");
89 } else if (bytes < GIBI) { // MiB
90 return formatUnits(bytes, MEBI, "MiB");
91 } else if (bytes < TEBI) { // GiB
92 return formatUnits(bytes, GIBI, "GiB");
93 } else if (bytes < PEBI) { // TiB
94 return formatUnits(bytes, TEBI, "TiB");
95 } else if (bytes < EXBI) { // PiB
96 return formatUnits(bytes, PEBI, "PiB");
97 } else { // EiB
98 return formatUnits(bytes, EXBI, "EiB");
99 }
100 }
101
102 /**
103 * Format units as exact integer or fractional decimal based on the prefix,

Callers 11

updateDatasetsMethod · 0.95
parseProcessesMethod · 0.95
printProcessesMethod · 0.95
printFileSystemMethod · 0.95
testFormatBytesMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95
toStringMethod · 0.95

Calls 1

formatUnitsMethod · 0.95

Tested by 4

printProcessesMethod · 0.76
printFileSystemMethod · 0.76
testFormatBytesMethod · 0.76