2
* Copyright 2010 SpringSource
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.springframework.build.aws.ant;
19
import java.text.DecimalFormat;
20
import java.text.NumberFormat;
23
* Base class with utility methods for all transfer type services.
27
abstract class TransferUtils {
29
private static final float KILOBYTE = 1024;
31
private static final float MEGABYTE = 1048576;
33
private static final float SECOND = 1000;
35
private static final NumberFormat formatter = new DecimalFormat("###,###.0");
37
private TransferUtils() {
40
public static String getFormattedSize(long size) {
41
StringBuilder sb = new StringBuilder();
42
float megabytes = size / MEGABYTE;
44
sb.append(formatter.format(megabytes));
48
float kilobytes = size / KILOBYTE;
49
sb.append(formatter.format(kilobytes));
55
public static String getFormattedTime(long time) {
56
StringBuilder sb = new StringBuilder();
57
float seconds = time / SECOND;
58
sb.append(formatter.format(seconds));
63
public static String getFormattedSpeed(long size, long time) {
64
StringBuilder sb = new StringBuilder();
65
float seconds = time / SECOND;
66
float megabytes = size / MEGABYTE;
67
float megabytesPerSecond = megabytes / seconds;
68
if (megabytesPerSecond > 1) {
69
sb.append(formatter.format(megabytesPerSecond));
73
float kilobytes = size / KILOBYTE;
74
float kilobytesPerSecond = kilobytes / seconds;
75
sb.append(formatter.format(kilobytesPerSecond));