[plug] Monitoring files "tail"

Craig Ringer craig at postnewspapers.com.au
Mon Nov 8 03:19:55 WST 2004


Adam Davin wrote:

>My question is then: how can I detect this change?
>
In a C program, I'd be interested in using dnotify / inotify to detect 
the change. It would be nice if Java made OS-specific change 
notification mechanisms availible via an abstracted interface, but I 
have no idea if it does. Sorry.

> For those who have used Java, I thought I might be able to query the file object (inFile.getAbsolutePath and inFile.getName() - where inFile is the file object), but this still seems to return the original name used to create the file.
>
It probably grabs the name when the file is opened, rather than querying 
the filesystem for it every time. There may be lower level (ie less 
portable) methods to query for the current name.

>I thought about creating a temporary file object with the filename to check the size of the new file against the old file, but this seems to be an awful lot of wasted overhead. 
>	File tempFile = new File("filename");
>	if (tempFile.length() < inFile.length()) {
>		.. close and reopen the file handle...
>	}
>
>Any thoughts would be greatly appreciated!
>  
>

On Linux, you can grab the inode number, then periodically compare the 
stored inode number to the new file. While inode numbers are not 
guaranteed not to be repeated, they will always be unique across the 
filesystem at any given point in time - so this should be safe. Again, 
though, this is almost certainly not portable beyond *NIX, and may not 
be reliably portable beyond Linux.

On another note - I'm currently working under Windows so I'm trying to 
get a handle on thunderbird. If this message comes through as HTML I'm 
very sorry - I'm forced to use the HTML composer (but it should be 
converting to plain text when it sends). I also noted that your mail 
client (Sylpheed? Don't see that often) doesn't seem to wrap text on 
messages it sends.

--
Craig Ringer




More information about the plug mailing list