Example usage for org.apache.wicket.util.lang Bytes terabytes

List of usage examples for org.apache.wicket.util.lang Bytes terabytes

Introduction

In this page you can find the example usage for org.apache.wicket.util.lang Bytes terabytes.

Prototype

public final double terabytes() 

Source Link

Document

Gets the byte count in terabytes.

Usage

From source file:eu.esdihumboldt.hale.server.projects.war.components.UploadForm.java

License:Open Source License

/**
 * Convert {@link Bytes} to a string, produces a prettier output than
 * {@link Bytes#toString(Locale)}/*from   ww w .  j a  va2 s .co m*/
 * 
 * @param bytes the bytes
 * @param locale the locale
 * 
 * @return the converted string
 */
public static String bytesToString(Bytes bytes, Locale locale) {
    if (bytes.bytes() >= 0) {
        if (bytes.terabytes() >= 1.0) {
            return unitString(bytes.terabytes(), "TB", locale);
        }

        if (bytes.gigabytes() >= 1.0) {
            return unitString(bytes.gigabytes(), "GB", locale);
        }

        if (bytes.megabytes() >= 1.0) {
            return unitString(bytes.megabytes(), "MB", locale);
        }

        if (bytes.kilobytes() >= 1.0) {
            return unitString(bytes.kilobytes(), "KB", locale);
        }

        return Long.toString(bytes.bytes()) + " bytes";
    } else {
        return "N/A";
    }
}