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

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

Introduction

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

Prototype

public final double gigabytes() 

Source Link

Document

Gets the byte count in gigabytes.

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  ava  2  s . c om
 * 
 * @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";
    }
}