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(); }
@Override public Map.Entry<StringPredicate,UserAuthzInformation> accept(String line) { line = line.trim(); if (line.isEmpty() || line.startsWith("#") || line.startsWith("version 2.")) { return null; } Matcher matcher = USER_MAP_FILE_LINE_PATTERN.matcher(line); try { if (matcher.lookingAt()) { final String key = matcher.group(UM_KEY_GROUP); final String access = matcher.group(UM_ACCESS_GROUP); final String uid = matcher.group(UM_UID_GROUP); final long[] gids = toLongs(matcher.group(UM_GID_GROUP).split(",")); final String home = stripQuotes(matcher.group(UM_HOME_GROUP)); final String root = stripQuotes(matcher.group(UM_ROOT_GROUP)); final String fsroot = stripQuotes(matcher.group(UM_FS_ROOT_GROUP)); String maxUploadValue = matcher.group("maxupload"); OptionalLong maxUpload = maxUploadValue == null ? OptionalLong.empty() : OptionalLong.of(ByteSizeParser.using(isoSymbol()).parse(maxUploadValue)); UserAuthzInformation info = new UserAuthzInformation(key, access, Long.parseLong(uid), gids, home, root, fsroot, maxUpload); return new SimpleImmutableEntry<>(new StringPredicate(key), info); } _log.warn("Ignored malformed line in AuthzDB-File: '{}'", line); } catch (NumberFormatException e) { _log.warn("Ignored malformed line '{}': {}", line, e.getMessage()); } return null; }
/** * 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"; }
double scaledMean = units.convert(mean, ByteUnit.BYTES); double scaledSem = units.convert(sem, ByteUnit.BYTES); meanDescription = "(" + toThreeSigFig(scaledMean, 1024, scaledSem) + ") " + isoSymbol().of(units);
double scaledSem = units.convert(sem, ByteUnit.BYTES); meanDescription = "(" + toThreeSigFig(scaledMean, 1024, scaledSem) + ") " + isoSymbol().of(units) + "/s";