1.

Solve : File Metadata and java?

Answer»

In windows xp when you right clicked a file and then clicked properties you could view a file's metadata. It had date created, modified ect. In another tab there was title, author, comment, etc.

In Linux I use thunar and there are different file properties, who has what access rights to the file and emblems, etc.

My questions are:
1: Are all the properties attached to the file, or are some in a database stuck to the operating system?
2. With java how do I access these properties?
3. Can I create my own properties and attach it inside of the file? Might be able to with an API:

https://msdn.microsoft.com/en-us/library/ms404384%28v=vs.110%29.aspxQuote from: TheWaffle on January 23, 2015, 11:22:57 AM

In windows xp when you right clicked a file and then clicked properties you could view a file's metadata. It had date created, modified ect. In another tab there was title, author, comment, etc.

In Linux I use thunar and there are different file properties, who has what access rights to the file and emblems, etc.

My questions are:
1: Are all the properties attached to the file, or are some in a database stuck to the operating system?
2. With java how do I access these properties?
3. Can I create my own properties and attach it inside of the file?

The properties you MENTION are stored in an alternate data stream on the file itself. Alternate Data streams are effectively files attached to the same filename, but as a sort of "subfile".



As luck would have it I fiddled about with this a few years ago. I didn't work on actually parsing the data in the properties, I was mostly interested in Alternate Data Streams (and less on specifically what they contained). So Even once you read the SummaryInformation data stream you would need

Programmatically, there are three ways to get the Alternate Data Stream information from the file. From a Java perspective it is important to note that ALL of these methods will involve the Win32 API. I can't remember how that is accessed from Java but I remember it being unpleasant.

You can either use ntQueryInformationFile to directly QUERY data from the file itself. This is a low level function. If you cannot do that for whatever reason, you can use BackupRead, and read the file as a Backup program would. Files opened with "Backup Semantics" Basically read in all the data for the file, including any alternate Data streams. The fun PART at that point is actually parsing the data and separating the various alternate data stream headers. Loads of fun because it is naturally not documented.

I wrote an implementation using ntQueryInformation File in VB6 here, but I doubt it will be very easy to port to Java. and Here is an implementation in the same language which uses the Backup functions.

Thankfully, this magic is only truly needed to see what data streams are present in a file. You can OPEN them without special logic... but, unfortunately, only when directly using the Win32API. Java (And .NET, and most languages) complain that the filename is invalid because it contains a colon. (you can specify alternate streams with a colon, such as "readme.txt:Zone.Identifier" but few programs support this.)






Discussion

No Comment Found