これが機能しない理由がわかりません:(メソッドはSOのHEREから取得されます)。
private String MakeSizeHumanReadable(int bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
String hr = String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
hr = hr.replace("-1 B", "n.a.");
return hr;
}
そして、これもありません:-
private String MakeSizeHumanReadable(int bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
String hr = String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
Pattern minusPattern = Pattern.compile("-1 B");
Matcher minusMatcher = minusPattern.matcher(hr);
if (minusMatcher.find()) {
return "n.a.";
} else {
return hr;
}
}
時々私-1 B
はリクエストから取得します(これは正常です)、それは決して変更されませんn.a.
(....私の質問)。
誰にもアイデアはありますか?