Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-294

Adding FileUtils.byteCountToDisplaySize(long size, boolean useSiUnits)

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1
    • None
    • Utilities
    • 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) {
      

      Attachments

        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

              Unassigned Unassigned
              jnrouvignac Jean-Noel Rouvignac
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: