public static String printUnitFromBytes(long bytes) {
        if (bytes < 0) {
            return "";
        }

        // http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
        int unit = 1000;
        if (bytes < unit) {
            return bytes + " B";
        }
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = String.valueOf("kMGTPE".charAt(exp - 1));
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }
@Test
    public void testPrintUnitFromBytes() {
        // needed for the locales that have a decimal separator other than comma
        char decimalSeparator = DecimalFormatSymbols.getInstance().getDecimalSeparator();

        assertEquals("999 B", printUnitFromBytes(999));
        assertEquals("1" + decimalSeparator + "0 kB", printUnitFromBytes(1000));
        assertEquals("1" + decimalSeparator + "0 kB", printUnitFromBytes(1001));
        assertEquals("1" + decimalSeparator + "2 kB", printUnitFromBytes(1201));

        assertEquals("1000" + decimalSeparator + "0 kB", printUnitFromBytes(999999));
        assertEquals("1" + decimalSeparator + "0 MB", printUnitFromBytes(1000000));
        assertEquals("1" + decimalSeparator + "0 MB", printUnitFromBytes(1000001));

        assertEquals("1" + decimalSeparator + "5 MB", printUnitFromBytes(1500001));
    }