[
https://issues.apache.org/jira/browse/IO-294?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Benedikt Ritter updated IO-294:
-------------------------------
Attachment: IO-294_FileSizeUnit.patch
Here's a proposal for introducing a new class called FileSizeUnit to [lang].
Currently I've only added the all possible file size units. The plan is to make
it work like {{java.util.concurrent.TimeUnit}} which lets you translate between
different temporal units.
I'm currently not sure how the api could look like.
* Is this class the place for formatting values (which was the request of this
ticket)? Or would we need a FileSizeUnitFormatter?
* What type will represent the actual size? {{Long.MAX_VALUE}} is 2^63 -1. 1
Pebibyte is 2^60 Bytes. {{Double.MAX_VALUE}} is (2-2^53) * 2^1023, which is big
enough, but feels strange for file sizes. OTOH if one wants to convert from a
Kilobyte value to Petabyte, the precision offered by double is useful...
> Adding FileUtils.byteCountToDisplaySize(long size, boolean useSiUnits)
> ----------------------------------------------------------------------
>
> Key: IO-294
> URL: https://issues.apache.org/jira/browse/IO-294
> Project: Commons IO
> Issue Type: New Feature
> Components: Utilities
> Affects Versions: 2.1
> Reporter: Jean-Noel Rouvignac
> Attachments: FileUtils.java, FileUtilsTest.java,
> IO-294_FileSizeUnit.patch
>
>
> I have written a little Utility method that might benefit Commons IO:
> {code}
> 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) {
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)