commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (IO-463) FileSystemUtils#freeSpace can be simplified by using new Java 6 File methods
Date Wed, 03 Dec 2014 16:22:12 GMT


Sebb commented on IO-463:

The {{freeSpace}} method Javadoc says:
Returns the free space on a drive or volume by invoking the command line. This method does
not normalize the result, and typically returns bytes on Windows, 512 byte units on OS X and
kilobytes on Unix. As this is not very useful, this method is deprecated in favour of freeSpaceKb(String)
which returns a result in kilobytes.

Note that some OS's are NOT currently supported, including OS/390, OpenVMS.

The free space is calculated via the command line. It uses 'dir /-c' on Windows and 'df' on

i.e. the units of the return value are not guaranteed; they may vary.

Does the wording actually guarantee a particular behaviour? i.e. are we breaking the contract
if we always return the value using a consistent unit?

If it really is considerd important to maintain the behaviour for this long-deprecated method,
then one possible solution might be to keep the OS detection for use with that method only,
and use it to determine the units to use, i.e. bytes on Windows and 512b on Unix. For other
OSes, the method should presumably continue to throw IllegalStateException.

> FileSystemUtils#freeSpace can be simplified by using new Java 6 File methods
> ----------------------------------------------------------------------------
>                 Key: IO-463
>                 URL:
>             Project: Commons IO
>          Issue Type: Improvement
>            Reporter: Sebb
> Commons IO now requires Java 1.6, which has some useful new File methods:
> File.getFreeSpace() / getUsableSpace()
> These could be used to radically simplify (and speed up) the FileSystemUtils freeSpace
methods, as well as making it OS-independent.
> The methods should be deprecated in favour of directly calling the File methods directly.
Perhaps even deprecate the entire class?  - it only contains the freeSpace methods currently.
> Note: a lot of the tests will becorme redundant or need reworking.

This message was sent by Atlassian JIRA

View raw message