class FileUtilities {

    public static String fileSizeUnits(final long length) {
        if (length < BYTES_IN_KILOBYTE) {
            return length + " B";
        }

        double size = (double) length;
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
        DecimalFormat format = (DecimalFormat) nf;
        format.applyPattern("####0.00");

        if (length < BYTES_IN_MEGABYTE) {
            return format.format(size / BYTES_IN_KILOBYTE) + " KB";
        } else if (length < BYTES_IN_GIGABYTE) {
            return format.format(size / BYTES_IN_MEGABYTE) + " MB";
        } else {
            return format.format(size / BYTES_IN_GIGABYTE) + " GB";
        }
    }

    private  FileUtilities();

}