OpenOption v. FileAttribute

Alan Bateman Alan.Bateman at Sun.COM
Fri Jan 22 09:40:18 PST 2010


On 20 Jan 2010, at 23:55, Salter, Thomas A wrote:

> What’s the intended distinction between OpenOption and  
> FileAttribute?  It seems like most functions that take OpenOption  
> also support an overload with FileAttribute, except for  
> Path.newOutputStream.
>
> It almost looks like OpenOption was intended to be for features that  
> only apply to the processing of the file and FileAttribute was to  
> specify permanent characteristics of the file.   
> StandardOpenOption.sparse would seem to be an exception.

That's right - open options specify how is opened and/or created. The  
FileAttribute[] parameter is to specify initial attributes/meta data  
when creating a file. The primary use-case is security attributes  
(permissions or an ACL) to eliminate the attack window that would  
otherwise arise if the file creation and setting the security  
attributes were separate operations. It could be used for setting the  
initial value of other file attributes/meta data but it's usually not  
as interesting.

The SPARSE open option is a platform independent "hint" when creating  
a file. Windows does expose it as an attribute, which might be why you  
mentioned this one, but there is no assumption in this API how it  
might be implemented or exposed.


>
> FileChannel.open (and similar functions) explicitly mention state  
> “An implementation may also support additional options.” under the  
> OpenOptions, but don’t make the same statement for FileAttribute.   
> Isn’t the intention those can be extended also?

Yes, and maybe we need to re-examine some of the wording here to make  
this clearer.


>
> Suppose my file system has a way to save the character encoding of a  
> text file (ASCII, EBCDIC, Unicode).  Should setting that be mapped  
> to an OpenOption or a FileAttribute?
>

In the API, the file contents are just a stream of bytes. You use a  
CharsetEncoder/Decoder to convert to/from chars. I don't anything  
about the file system you are thinking of, but it sounds like the  
charset encoding is an attribute might map to the appropriate Charset  
when reading the file - is that right?

-Alan

-Alan.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20100122/7b0f3295/attachment.html 


More information about the nio-discuss mailing list