Commons IO
  1. Commons IO
  2. IO-294

Adding FileUtils.byteCountToDisplaySize(long size, boolean useSiUnits)

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: Utilities
    • Labels:
      None

      Description

      I have written a little Utility method that might benefit Commons IO:

      public class FileUtils {
      
          /**
           * Returns a human-readable version of the file size (original is in bytes). The implementation has the following features:
           * <ul>
           * <li>Supports the SI or IEC units.</li>
           * <li>Supports I18n</li>
           * <li>Display a one digit remainder (rounded down if less than 5, rounded up otherwise)</li>
           * <li>Once the main unit is >= 100, drops the remainder which would be over precision.</li>
           * </ul>
           * 
           * @param size The number of bytes.
           * @param useSiUnits if false, uses the IEC (International Electrotechnical Commission) units (powers of 2), else uses SI (International System of Units)
           *            units (powers of 10).
           * @return A human-readable display value (includes units).
           */
          public static String byteCountToDisplaySize(long size, boolean useSiUnits) {
      
      1. IO-294_FileSizeUnit.patch
        3 kB
        Benedikt Ritter
      2. FileUtilsTest.java
        4 kB
        Jean-Noel Rouvignac
      3. FileUtils.java
        2 kB
        Jean-Noel Rouvignac

        Issue Links

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Jean-Noel Rouvignac
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Development