(long size, String format)
| 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 | } |
no test coverage detected