/** * Convert a passed byte string (e.g. 50b, 100k, or 250m) to gibibytes for * internal use. * <p> * If no suffix is provided, the passed number is assumed to be in gibibytes. */ public static long byteStringAsGb(String str) { return byteStringAs(str, ByteUnit.GiB); }
/** * Convert a time parameter such as (50s, 100ms, or 250us) to seconds for internal use. If * no suffix is provided, the passed number is assumed to be in seconds. */ public static long timeStringAsSec(String str) { return timeStringAs(str, TimeUnit.SECONDS); }
public long toMiB(long d) { return convertTo(d, MiB); }
public static void deleteRecursively(File file) throws IOException { if (file == null) { return; } if (file.isDirectory() && !isSymlink(file)) { IOException savedIOException = null; for (File child : listFilesSafely(file)) { try { deleteRecursively(child); } catch (IOException e) { // In case of multiple exceptions, only last one will be thrown savedIOException = e; } } if (savedIOException != null) { throw savedIOException; } } boolean deleted = file.delete(); // Delete can also fail if the file simply did not exist. if (!deleted && file.exists()) { throw new IOException("Failed to delete: " + file.getAbsolutePath()); } }
row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable), c.getCharset().getResults())); row.add(StringUtil.encode(JavaUtils.bytesToString2(usedForNetwork), c.getCharset().getResults())); row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable - usedForNetwork), c.getCharset().getResults()));
public long convertTo(long d, ByteUnit u) { if (multiplier > u.multiplier) { long ratio = multiplier / u.multiplier; if (Long.MAX_VALUE / ratio < d) { throw new IllegalArgumentException("Conversion of " + d + " exceeds Long.MAX_VALUE in " + name() + ". Try a larger unit (e.g. MiB instead of KiB)"); } return d * ratio; } else { // Perform operations in this order to avoid potential overflow // when computing d * multiplier return d / (u.multiplier / multiplier); } }
return unit.convertFrom(val, suffix != null ? BYTE_SUFFIXES.get(suffix) : unit); } else if (fractionMatcher.matches()) { throw new NumberFormatException("Fractional values are not supported. Input was: " +
public long toGiB(long d) { return convertTo(d, GiB); }
/** * Convert a passed byte string (e.g. 50b, 100k, or 250m) to mebibytes for * internal use. * <p> * If no suffix is provided, the passed number is assumed to be in mebibytes. */ public static long byteStringAsMb(String str) { return byteStringAs(str, ByteUnit.MiB); }
/** * Convert a time parameter such as (50s, 100ms, or 250us) to milliseconds for internal use. If * no suffix is provided, the passed number is assumed to be in ms. */ public static long timeStringAsMs(String str) { return timeStringAs(str, TimeUnit.MILLISECONDS); }
row.add(StringUtil.encode(value > 0 ? JavaUtils.bytesToString2(value) : "0", c.getCharset().getResults()));
public long toPiB(long d) { return convertTo(d, PiB); }
/** * Convert a passed byte string (e.g. 50b, 100k, or 250m) to bytes for * internal use. * <p> * If no suffix is provided, the passed number is assumed to be in bytes. */ public static long byteStringAsBytes(String str) { return byteStringAs(str, ByteUnit.BYTE); }
public long convertFrom(long d, ByteUnit u) { return u.convertTo(d, this); }
/** * Convert a passed byte string (e.g. 50b, 100k, or 250m) to kibibytes for * internal use. * <p> * If no suffix is provided, the passed number is assumed to be in kibibytes. */ public static long byteStringAsKb(String str) { return byteStringAs(str, ByteUnit.KiB); }
public long toKiB(long d) { return convertTo(d, KiB); }
public long toTiB(long d) { return convertTo(d, TiB); }