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

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

Introduction

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

Prototype

public final double megabytes() 

Source Link

Document

Gets the byte count in megabytes.

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)}//w w  w  .j  a va2  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";
    }
}