InterviewSolution
| 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 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. 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.) |
|