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

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

Introduction

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

Prototype

public final double kilobytes() 

Source Link

Document

Gets the byte count in kilobytes.

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.ja  v a 2  s. c  o  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";
    }
}

From source file:org.hippoecm.frontend.plugins.standards.diff.DefaultHtmlDiffService.java

License:Apache License

@Override
public String diff(final String originalValue, final String currentValue) {
    Bytes maxDiffSize = Bytes.valueOf(params.getString(MAX_DIFF_SIZE, DEFAULT_MAX_DIFF_SIZE));
    final int maxLenSize = Math.max(originalValue.length(), currentValue.length());

    try {/*from   w w w  .jav a 2  s . c o  m*/
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (maxLenSize <= maxDiffSize.bytes()) {
            DiffHelper.diffHtml(originalValue, currentValue, new StreamResult(baos), Session.get().getLocale());
            return baos.toString("UTF-8");
        } else {
            log.warn("Unable to diff a large content of size {} KB, which is exceeds the limitation {} KB ",
                    Bytes.bytes(maxLenSize).kilobytes(), maxDiffSize.kilobytes());
        }
    } catch (TransformerConfigurationException e) {
        log.error(e.getMessage(), e);
    } catch (SAXException e) {
        log.info(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    return null;
}