Sunday, March 16, 2014

JavaSE: How to SET/GET your own Files and Directory Attributes

In the previous article "Determining Views Supported by a Particular File System" and see how to ask the file system store, and see supportability of a particular file attribute view.

We are going to explore in a nutshell, one of the most advanced and important files attribute views which is User-Defined File Attributes View.

Particularly, I am using this feature a lot in my exchanged files during integration between my systems, to hide my files meta-data and security related information from users and contents of the file. So the file content will be only regarding the content of the file only, no more irrelevant meta-data.

Therefore If you find that there are not enough built-in attributes for your needs or if you have some unique meta-data (meaningful to the file system) that you want to associate with a file, you can define your own attributes.

NIO.2 offers the user-defined file attributes view, extended attributes through the UserDefinedFileAttributeView interface. This facility allows you to associate to a file any attribute that you consider to be useful for your use cases.

Here you should know how to:

  1. Check User-Defined Attributes Supportability
  2. Operations on User-Defined Attributes as the following:
    1. Define a User Attribute.
    2. List User-Defined Attribute Names and Value Sizes.
    3. Get the Value of a User-Defined Attribute.
    4. Delete a File’s User-Defined Attribute.

Here is the class that has operations defined previously, also you need to use JDK 7+:


No comments :

Post a Comment