@Override public int width(Object value) { if (abbrev && value != null) { return DECIMAL.unitsOf((long) value) == BYTES ? 4 : 5; } else { return Objects.toString(value, "").length(); } }
private void render(long value, int actualWidth, PrintWriter out) { ByteUnit units = DECIMAL.unitsOf(value); String symbol = isoSymbol().of(units); String numerical = render(value, units); int padding = actualWidth - numerical.length() - symbol.length(); while (padding-- > 0) { out.append(' '); } out.append(numerical).append(symbol); }
/** * Provide a description of a file/data size (in bytes). The output shows * the exact number with units ("B"). If the value is larger than 1 KiB * then the scaled value is shown in the most appropriate units. For * example 10 --> "10 B", 2560 --> "2560 B (2.5 KiB)". * @param size The size to represent. * @return a String describing this value. */ public static String describeSize(long size) { StringBuilder sb = new StringBuilder(); sb.append(size).append(' ').append(isoSymbol().of(ByteUnit.BYTES)); ByteUnit units = BINARY.unitsOf(size); if (units != ByteUnit.BYTES) { sb.append(" (").append(toThreeSigFig(units.convert((double)size, ByteUnit.BYTES), 1024)) .append(' ').append(isoSymbol().of(units)).append(')'); } return sb.toString(); }
meanDescription = describeSize(Math.round(mean)); } else { ByteUnit units = BINARY.unitsOf(mean); double scaledMean = units.convert(mean, ByteUnit.BYTES); double scaledSem = units.convert(sem, ByteUnit.BYTES);
meanDescription = describeBandwidth(mean); } else { ByteUnit units = BINARY.unitsOf(mean); double scaledMean = units.convert(mean, ByteUnit.BYTES); double scaledSem = units.convert(sem, ByteUnit.BYTES);
/** * Provide a file/data size (in bytes) a human readable form, using binary units * and ISO symbols. For example, 10 --> "10 B", 2560 --> "2.5 KiB". * @param size The size to represent. * @return a String describing this value. */ public static String humanReadableSize(long size) { ByteUnit units = BINARY.unitsOf(size); return toThreeSigFig(units.convert((double)size, ByteUnit.BYTES), 1024) + " " + isoSymbol().of(units); }
/** * Provide a human-readable description of a bandwidth value, using binary * prefixes (2^10, 2^20, ...) and ISO symbols (KiB/s, MiB/s, ...). A * typical description is 36280729 --> "34.6 MiB/s" * @param value the bandwidth value, in bytes per second * @return a human understandable description of that bandwidth */ public static String describeBandwidth(double value) { ByteUnit units = BINARY.unitsOf(value); return toThreeSigFig(units.convert((double)value, ByteUnit.BYTES), 1024) + " " + isoSymbol().of(units) + "/s"; }
/** * Returns which units to use when describing this value. More * specifically, it returns the ByteUnit prefix that, when * {@code convert(value, ByteUnit.BYTES);} is called, returns at least * 1. If {@literal value} is zero then ByteUnit.BYTES is returned. */ public ByteUnit unitsOf(double value) { return unitsOf(value, 1d); }
/** * Returns which units to use when describing this value. More * specifically, it returns the ByteUnit prefix that, when * {@code convert(value, ByteUnit.BYTES);} is called, returns the * smallest absolute non-zero value. * If {@literal value} is zero then ByteUnit.BYTES is returned. */ public ByteUnit unitsOf(long value) { return unitsOf(value, 1L); }