/** * Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive. * * <pre> * 1 == 1 byte * 1b == 1 byte * 1k == 1 kilobyte == 1024 bytes == 1,024 bytes * 1m == 1 megabyte == 1024^2 bytes == 1,048,576 bytes * 1g == 1 gigabyte == 1024^3 bytes == 1,073,741,824 bytes * 1t == 1 terabyte == 1024^4 bytes == 1,099,511,627,776 bytes * 1p == 1 petabyte == 1024^5 bytes == 1,125,899,906,842,624 bytes * 1e == 1 exabyte == 1024^6 bytes == 1,152,921,504,606,846,976 bytes * </pre> */ public static long getBytes(String size) { return getBytes(size, SIZE_TOKENS, BASE); }
@Override public Long getObject() { Assert.notNull(size, "size is null"); return FormatUtils.getBytes(size); }
/** * Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive. * * @see FormatUtils.getBytes(String size) */ public static long getBytes(Environment env, String key) { String value = getProperty(env, key); return FormatUtils.getBytes(value); }
/** * Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive. * * @see FormatUtils.getBytes(String size) */ public static long getBytes(Environment env, String key, String defaultValue) { String value = getProperty(env, key, defaultValue); return FormatUtils.getBytes(value); }
public Builder maxBytes(String maxBytes) { return maxBytes(Optional.of(FormatUtils.getBytes(maxBytes))); }
/** * If the environment contains a string under this key, convert it into a long signifying bytes * * <pre> * file.size=10m (file that is 10 megabytes) * disk.size=100g (disk that is 100 gigabytes) * </pre> */ public static long getBytes(EnvironmentService env, String key, long provided) { if (env.containsProperty(key)) { String size = env.getString(key); long bytes = FormatUtils.getBytes(size); return bytes; } else { return provided; } }