/** * 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 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()));
row.add(StringUtil.encode(value > 0 ? JavaUtils.bytesToString2(value) : "0", c.getCharset().getResults()));
/** * 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); }
/** * 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); }
/** * 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); }