MCPcopy Create free account
hub / github.com/apache/tomcat / formatSize

Method formatSize

java/org/apache/catalina/ssi/SSIFsize.java:100–125  ·  view source on GitHub ↗
(long size, String format)

Source from the content-addressed store, hash-verified

98 // All the 'magic' numbers are from the util_script.c httpd source file.
99 // Should use KiB and MiB in output but use k and M for consistency with httpd.
100 private String formatSize(long size, String format) {
101 String retString;
102 if (format.equalsIgnoreCase("bytes")) {
103 DecimalFormat decimalFormat = new DecimalFormat("#,##0");
104 retString = decimalFormat.format(size);
105 } else {
106 if (size < 0) {
107 retString = "-";
108 } else if (size == 0) {
109 retString = "0k";
110 } else if (size < ONE_KIBIBYTE) {
111 retString = "1k";
112 } else if (size < ONE_MEBIBYTE) {
113 retString = Long.toString((size + 512) / ONE_KIBIBYTE);
114 retString += "k";
115 } else if (size < 99 * ONE_MEBIBYTE) {
116 DecimalFormat decimalFormat = new DecimalFormat("0.0M");
117 retString = decimalFormat.format(size / (double) ONE_MEBIBYTE);
118 } else {
119 retString = Long.toString((size + (529 * ONE_KIBIBYTE)) / ONE_MEBIBYTE);
120 retString += "M";
121 }
122 retString = padLeft(retString, 5);
123 }
124 return retString;
125 }
126}

Callers 1

processMethod · 0.95

Calls 4

padLeftMethod · 0.95
formatMethod · 0.65
toStringMethod · 0.65
equalsIgnoreCaseMethod · 0.45

Tested by

no test coverage detected