The class java.io.File surprisingly lacks a method named: getOwner
We can get the size, whether it's a directory, whether it's readable, whether it's writable, the file name, etc. Why not the owner name?
The signature ought to be: public String getOwner();
One consideration is that the concept of file ownership differs from system to system, and is absent in some systems. That's handlable.
Of the systems that have file ownership, they all can retrieve a printable owner name. On Unix where you can have multiple user names for the same user ID, I suggest making the user name returned be the first one found in the password file (or other user name lookup means). If the user name cannot be found or is otherwise unsupported, then return the numerical user ID as a string.
If file ownership does not exist on the system at all, you can return null. Since you're gauranteed to return a non-null String if the concept of file ownership does exist, then returning null is a clear indication that the concept of file ownership does not exist.
There might be a hypothetical case to be made for a system that supports multiple file owners. I don't know of such a system, so it's probably much too pedantic a case. Especially since I can't think of a good use for having multiple file owners.
We can get the size, whether it's a directory, whether it's readable, whether it's writable, the file name, etc. Why not the owner name?
The signature ought to be: public String getOwner();
One consideration is that the concept of file ownership differs from system to system, and is absent in some systems. That's handlable.
Of the systems that have file ownership, they all can retrieve a printable owner name. On Unix where you can have multiple user names for the same user ID, I suggest making the user name returned be the first one found in the password file (or other user name lookup means). If the user name cannot be found or is otherwise unsupported, then return the numerical user ID as a string.
If file ownership does not exist on the system at all, you can return null. Since you're gauranteed to return a non-null String if the concept of file ownership does exist, then returning null is a clear indication that the concept of file ownership does not exist.
There might be a hypothetical case to be made for a system that supports multiple file owners. I don't know of such a system, so it's probably much too pedantic a case. Especially since I can't think of a good use for having multiple file owners.
- duplicates
-
JDK-4313887 New I/O: Improved filesystem interface
- Resolved