新增获取磁盘主机的信息
This commit is contained in:
@@ -6,7 +6,6 @@ import com.mini.capi.biz.domain.DiskMount;
|
||||
import com.mini.capi.biz.domain.SysHost;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
public final class HostInfo {
|
||||
@@ -67,7 +66,7 @@ public final class HostInfo {
|
||||
return out.toString().trim();
|
||||
}
|
||||
|
||||
private static void waitForExit(ChannelExec ch) throws Exception {
|
||||
private static void waitForExit(ChannelExec ch) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!ch.isClosed()) {
|
||||
if (System.currentTimeMillis() - start > 30_000) {
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
package com.mini.capi.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class vF {
|
||||
|
||||
|
||||
|
||||
private static final String[] UNITS = {"B", "K", "M", "G", "T", "P"};
|
||||
|
||||
private static final BigDecimal KB = BigDecimal.valueOf(1024L);
|
||||
|
||||
public static String format(long bytes) {
|
||||
if (bytes < 0) {
|
||||
throw new IllegalArgumentException("字节数不能为负数");
|
||||
}
|
||||
|
||||
BigDecimal size = BigDecimal.valueOf(bytes);
|
||||
int unitIndex = 0;
|
||||
double size = bytes;
|
||||
|
||||
while (size >= 1024 && unitIndex < UNITS.length - 1) {
|
||||
size /= 1024;
|
||||
while (size.compareTo(KB) >= 0 && unitIndex < UNITS.length - 1) {
|
||||
size = size.divide(KB, 2, RoundingMode.HALF_UP);
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
// 保留最多一位小数,去掉多余的 .0
|
||||
return String.format("%.1f", size).replace(".0", "") + UNITS[unitIndex];
|
||||
String num = size.stripTrailingZeros().toPlainString();
|
||||
return num + UNITS[unitIndex];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user