NIO feedback

John Hendrikx hjohn at xs4all.nl
Wed Oct 14 09:22:38 PDT 2009


I hope you don't mind me sending to the list, but I figured I'd share 
some things while working with NIO2 and perhaps gain a bit more insight 
in its workings.  The project I'm working on may be a slightly unusual 
use-case for NIO2 in that it isn't just an application that wants to 
access the filesystem.  It is more of a file management system.

Reading Attributes:

I found there is no way to just get all attributes that a filesystem can 
provide, or find out what the "most specific" AttributeView is that a 
filesystem provides.  Something like:

  path.getAttributes("*:*");

is not allowed.  That's ok, so I went looking for a way to figure out 
what system I'm running on... should I get "dos:*" or "posix:*" or even 
something else entirely.. I don't know.  The Linux system I use here 
gives me the following possible views when I do:

 path.getFileSystem().supportedFileAttributeViews();

It results in [basic, owner, user, dos, unix, posix] which confuses me.  
Why is "dos" in there?  So I tried querying it.  I get a 
FileSystemException (/temp: Operation not supported).

For now in my application I simply query several views. Any that throw 
an exception or result in an empty map are ignored.  I'm left wondering 
if there is a better way.

Writing Attributes:

Above I managed to read the attributes in some fashion.  Now I want to 
set them.  I discovered some of the attributes (like "attributes" in 
dos) are read only.  So instead I query 
"readOnly,hidden,archive,system", not really optimal.  Especially 
because I cannot find a way to set multiple attributes at once.  I'm 
left with:

  for(String key : attributes.keySet()) {
     destinationPath.setAttribute(type + ":" + key, attributes.get(key), 
LinkOption.NOFOLLOW_LINKS);
  }

Again, is there a better way?  What I'm trying to achieve is to simply 
make an exact copy of a file, including most attributes, 
lastModifiedTime, ACL's and owner/group information.  Setting half a 
dozen attributes in a row seems akward.

ACL:

I cannot read ACL's at all under Linux (ext3), I get an 
UnsupportedOperationException.  I hope support for this is still 
forthcoming.

copyTo/moveTo:

These are not very useful for me, I'd like to give feedback during this 
process (progress indicator). 

Also, I really miss a rename function on the Path class.  Currently it 
is important for my application to know when a moveTo will simply be a 
quick rename, or when it involves actually doing a copy (in which case I 
want to do it manually to give progress information).   I have to 
compare FileStores to see if it will be a copy or just a plain rename 
(not sure how much of a guarantee that is though).  The ATOMIC_MOVE 
option is unclear whether this will mean "just a rename" and/or "yes 
we'll do an-hour-long-copy transactionally if the filesystem supports it".

Still, NIO2 is definitely allowing me to do what I want with the various 
filesystems out there.  Sometimes it feels a little akward, but I've not 
found anything yet that I couldn't achieve with it.

Any tips are appreciated :)
--John













More information about the nio-dev mailing list