- Timestamp:
- 2016-01-03T12:13:44+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/StreamProgressUpdater.java
r9197 r9274 2 2 package org.openstreetmap.josm.io; 3 3 4 import java.util.Locale; 5 4 6 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 5 7 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 8 import org.openstreetmap.josm.tools.Utils; 6 9 7 10 final class StreamProgressUpdater { … … 45 48 progressMonitor.setTicks(soFar); 46 49 } 47 progressMonitor.setExtraText( soFar / 1024 + " KB");50 progressMonitor.setExtraText(Utils.getSizeString(soFar, Locale.getDefault())); 48 51 } 49 52 } -
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9255 r9274 13 13 import java.net.URL; 14 14 import java.util.List; 15 import java.util.Locale; 15 16 import java.util.Map; 16 17 import java.util.Scanner; … … 99 100 100 101 if ("PUT".equals(requestMethod) || "POST".equals(requestMethod) || "DELETE".equals(requestMethod)) { 101 Main.info("{0} {1} ({2} kB) ...", requestMethod, url, requestBody.length / 1024);102 Main.info("{0} {1} ({2}) ...", requestMethod, url, Utils.getSizeString(requestBody.length, Locale.getDefault())); 102 103 headers.put("Content-Length", String.valueOf(requestBody.length)); 103 104 connection.setDoOutput(true); … … 116 117 requestMethod, url, hasReason ? " (" + reasonForRequest + ")" : "", 117 118 connection.getResponseCode(), 118 connection.getContentLengthLong() > 0 ? " (" + connection.getContentLengthLong() / 1024 + "KB)" : "" 119 connection.getContentLengthLong() > 0 120 ? " (" + Utils.getSizeString(connection.getContentLengthLong(), Locale.getDefault()) + ")" 121 : "" 119 122 ); 120 123 if (Main.isDebugEnabled()) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9246 r9274 1146 1146 1147 1147 /** 1148 * Returns a human readable representation (B, kB, MB, ...) for the given number of byes. 1149 * @param bytes the number of bytes 1150 * @param locale the locale used for formatting 1151 * @return a human readable representation 1152 * @since 9274 1153 */ 1154 public static String getSizeString(long bytes, Locale locale) { 1155 if (bytes < 0) { 1156 throw new IllegalArgumentException("bytes must be >= 0"); 1157 } 1158 final String[] units = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; 1159 int unitIndex = 0; 1160 double value = bytes; 1161 while (value >= 1024 && unitIndex < units.length) { 1162 value /= 1024; 1163 unitIndex++; 1164 } 1165 if (value > 100 || unitIndex == 0) { 1166 return String.format(locale, "%.0f %s", value, units[unitIndex]); 1167 } else if (value > 10) { 1168 return String.format(locale, "%.1f %s", value, units[unitIndex]); 1169 } else { 1170 return String.format(locale, "%.2f %s", value, units[unitIndex]); 1171 } 1172 } 1173 1174 /** 1148 1175 * Returns a human readable representation of a list of positions. 1149 1176 * <p>
Note:
See TracChangeset
for help on using the changeset viewer.