Accessing extended file attributes without the 'user' prefix: impossibile?

99 views Asked by At

It seems that Java (Java 17 and 20) is not able to read extended file attributes not having the prefix user in their name. I've done my research and test, but I'd like to have a confirmation before proceeding with a B-plan for my application.

More in detail: what I need is to read and write my own extended attributes to files. This is done by means of the UserDefinedFileAttributeView view, e.g.:

final var view = Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
log.info("file: {} attributes {}", file, view.list());

My attributes are named it.tidalwave.datamanager.id, etc.; they have been handled so far by a Python application I wrote a few years ago (I'm porting it to Java before further development).

What it turns out is that Java internally retrieves the attributes, but filters away those whose names are not prefixed by user (this is obliquely mentioned in the code examples in the javadocs). A debugging screenshot of the involved JDK code proves this:

debugging screenshot

Furthermore, in the method that transforms the attribute name to the byte array expected by the native code, user. is explicitly prefixed.

I'm not aware of other ways to query extended attributes of files; other kinds of file attribute views are (such as PosixFileAttributeView) restricted to standard filesystem stuff. I've also tested it on Java 20, it's unchanged, and I'm not aware of new APIs in this context.

I'd like to have a confirmation.

0

There are 0 answers