Clover Coverage Report - AWS S3 Wagon 1.0.33
Coverage timestamp: Wed Nov 9 2011 17:02:59 EST
../../../../img/srcFileCovDistChart3.png 10% of files have more coverage
32   84   10   8
12   60   0.31   4
4     2.5  
1    
 
  SimpleFormatter       Line # 13 32 0% 10 37 22.9% 0.22916667
 
  (1)
 
1    package org.kuali.maven.wagon;
2   
3    import java.text.NumberFormat;
4   
5    import org.apache.commons.lang.StringUtils;
6   
7    /**
8    * Very simple formatter for formatting a few things - transfer rate, elapsed time, bytes
9    *
10    * @author Jeff Caddel
11    * @since May 27, 2010 6:46:17 PM
12    */
 
13    public class SimpleFormatter {
14    private static final double KB = 1024;
15    private static final double MB = 1024 * KB;
16    private static final double GB = 1024 * MB;
17    private static final double ONE_SECOND = 1000;
18    private static final double ONE_MINUTE = 60 * ONE_SECOND;
19    private static final double FIFTEEN_MINUTES = 15 * ONE_MINUTE;
20   
21    NumberFormat sizeFormatter = NumberFormat.getInstance();
22    NumberFormat timeFormatter = NumberFormat.getInstance();
23    NumberFormat rateFormatter = NumberFormat.getInstance();
24   
 
25  1 toggle public SimpleFormatter() {
26  1 super();
27  1 sizeFormatter.setGroupingUsed(false);
28  1 sizeFormatter.setMaximumFractionDigits(1);
29  1 sizeFormatter.setMinimumFractionDigits(1);
30  1 timeFormatter.setGroupingUsed(false);
31  1 timeFormatter.setMaximumFractionDigits(3);
32  1 timeFormatter.setMinimumFractionDigits(3);
33  1 rateFormatter.setGroupingUsed(false);
34  1 rateFormatter.setMaximumFractionDigits(1);
35  1 rateFormatter.setMinimumFractionDigits(1);
36    }
37   
38    /**
39    * Given milliseconds and bytes return kilobytes per second
40    */
 
41  0 toggle public String getRate(final long millis, final long bytes) {
42  0 int pad = 1;
43  0 double seconds = millis / 1000D;
44  0 double kilobytes = bytes / 1024D;
45  0 double kilobytesPerSecond = kilobytes / seconds;
46  0 if (kilobytesPerSecond < 1024) {
47  0 return StringUtils.leftPad(rateFormatter.format(kilobytesPerSecond) + " kB/s", pad, " ");
48    } else {
49  0 double transferRate = kilobytesPerSecond / 1024;
50  0 return StringUtils.leftPad(rateFormatter.format(transferRate) + " MB/s", pad, " ");
51    }
52    }
53   
54    /**
55    * Given milliseconds, return seconds or minutes
56    */
 
57  0 toggle public String getTime(final long millis) {
58  0 int pad = 1;
59  0 if (millis < ONE_SECOND) {
60  0 return StringUtils.leftPad(millis + "ms", pad, " ");
61  0 } else if (millis < 10 * ONE_SECOND) {
62  0 return StringUtils.leftPad(timeFormatter.format(millis / ONE_SECOND) + "s", pad, " ");
63  0 } else if (millis < FIFTEEN_MINUTES) {
64  0 return StringUtils.leftPad(rateFormatter.format(millis / ONE_SECOND) + "s", pad, " ");
65    } else {
66  0 return StringUtils.leftPad(rateFormatter.format(millis / ONE_MINUTE) + "m", pad, " ");
67    }
68    }
69   
70    /**
71    * Given bytes, return kilobytes if it is less than a megabyte, megabytes if it is less than a gigabyte, otherwise
72    * gigabytes
73    */
 
74  0 toggle public String getSize(final long bytes) {
75  0 int pad = 1;
76  0 if (bytes < MB) {
77  0 return StringUtils.leftPad(sizeFormatter.format(bytes / KB) + "k", pad, " ");
78    }
79  0 if (bytes < GB) {
80  0 return StringUtils.leftPad(sizeFormatter.format(bytes / MB) + "m", pad, " ");
81    }
82  0 return StringUtils.leftPad(sizeFormatter.format(bytes / GB) + "g", pad, " ");
83    }
84    }