You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
907 B
Java
38 lines
907 B
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.codelistmappingimportwidget.client.util;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi"
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class Format {
|
|
|
|
/**
|
|
* Converts a file size into a {@link String} representation adding the misure unit.
|
|
* @param size the file size.
|
|
* @return the textual representation.
|
|
*/
|
|
public static String fileSize(long size) {
|
|
StringBuilder text = new StringBuilder();
|
|
if (size < 1024) {
|
|
text.append(size);
|
|
text.append(" bytes");
|
|
} else if (size < 1048576) {
|
|
text.append(Math.round(((size * 10) / 1024)) / 10);
|
|
text.append(" KB");
|
|
} else if (size < 1073741824) {
|
|
text.append(Math.round(((size * 10) / 1048576)) / 10);
|
|
text.append(" MB");
|
|
} else {
|
|
text.append(Math.round(((size * 10) / 1073741824)) / 10);
|
|
text.append(" GB");
|
|
}
|
|
return text.toString();
|
|
}
|
|
|
|
}
|