/** * 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); }
public ColumnWriter date(String name) { addColumn(new DateColumn(name)); return this; }
public ColumnWriter left(String name) { addColumn(new LeftColumn(name)); return this; }
/** * Injects the options default values for options into {@code object} using the * Option annotation of fields of {@code <T>}. * * @param object Target object to inject options into. * @param <T> Type of the target object. * @return Returns {@code object}. */ public static <T> T injectDefaults(T object) { return inject(new Args(new String[0]), object); }
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); }
/** * @param inetAddress address to be checked against the subnet * @return true if inetAddress is contained in the subnet represented by this instance, otherwise false */ public boolean contains(InetAddress inetAddress) { return IPMatcher.match(inetAddress, getSubnetAddress(), getMask() ); }
public ColumnWriter right(String name) { addColumn(new RightColumn(name)); return this; }
public ColumnWriter fixed(String value) { addColumn(new FixedColumn(value)); return this; }
public ColumnWriter bytes(String name) { addColumn(new ByteColumn(name)); return this; }
public ColumnWriter centre(String name) { addColumn(new CentreColumn(name)); return this; }
public int toKiB(int d) { if (d == Integer.MAX_VALUE) { return d; } return checkedCast(toKiB((long) d)); }
public int toGB(int d) { if (d == Integer.MAX_VALUE) { return d; } return checkedCast(toGB((long) d)); }
/** * Unfolds alternations (brace lists) into a list. */ public static Iterable<String> expandGlob(String glob) { return new GlobBraceParser(glob).expandGlob(); }
public int toPB(int d) { if (d == Integer.MAX_VALUE) { return d; } return checkedCast(toPB((long) d)); }
/** * @param inetAddresses addresses to be checked against the subnet * @return true if any of the inetAddresses is contained in the subnet represented by this instance, otherwise false */ public boolean containsAny(InetAddress[] inetAddresses) { for (InetAddress inetAddress : inetAddresses) { if (contains(inetAddress)) { return true; } } return false; }
/** * Obtain the TCP port number from the URI. If the port number is * defined in the URI then that value is used. If the URI contains no * port number but a default value is known for the schema, then that * default value is returned; otherwise, otherwise -1 is returned. */ public static int portWithDefault(URI uri) { return portWithDefault(uri, null, -1); }
/** * Return a URI with a defined port number, if possible. Default port * numbers are used are used if the URI has no port number and a default * port is known for this scheme. */ public static URI withDefaultPort(URI uri) { return withDefaultPort(uri, null, -1); }
/** * 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"; }
public ColumnWriter date(String name, DateStyle style) { addColumn(new DateColumn(name, style)); return this; }