[io] FileMonitor. How to deal with a huge file whom copy is longer than file monitor checkAndNotify call frequency

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[io] FileMonitor. How to deal with a huge file whom copy is longer than file monitor checkAndNotify call frequency

Damien Tacheron
Hi,

i have some problems : when my listener is trigered with OnCreate event by
FileAlterationObserver, i start to copy the new file but in fact the file is
not complete because copy is running (windows system)

i'm lookin how to deal with this.

Someone can help me to achieve this ?

Best regards



 *Damien Tacheron*
Chef de projet
------------------------------
SQLI Paris
standard : 01 55 93 26 00
ligne directe : 01 55 93 02 51
<[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [io] FileMonitor. How to deal with a huge file whom copy is longer than file monitor checkAndNotify call frequency

JavaDev7
Hi,

on windows, it is simple to detect if file was copied or is copying..
You should start thread and check if you can obtain lock on file if not
you sleep on some period and then try again..

Try:
FileChannel fileChannel = file.getChannel();
 fileLock = fileChannel.tryLock();
            if (fileLock != null){
                System.out.println("File is locked");
                accessTheLockedFile();
            }

Here is link with sample code: http://www.javabeat.net/tips/37-locking-files-using-java.html

The problem is on linux where you can obtain lock on copying file..
We solved this problem by renaming file with correct extension after copying was complete...
Reply | Threaded
Open this post in threaded view
|

Re: [io] FileMonitor. How to deal with a huge file whom copy is longer than file monitor checkAndNotify call frequency

ipsi
I believe that is how rsync works on Linux too, for example, - when
copying, it creates a hidden file with some random suffix added to the
file name, and then when the transfer is complete it will just rename
the file. At which point, I would assume you'd be notified that the
file was there.

- Andrew

On Wed, Apr 27, 2011 at 7:48 PM, JavaDev7 <[hidden email]> wrote:

> Hi,
>
> on windows, it is simple to detect if file was copied or is copying..
> You should start thread and check if you can obtain lock on file if not
> you sleep on some period and then try again..
>
> Try:
> FileChannel fileChannel = file.getChannel();
>  fileLock = fileChannel.tryLock();
>            if (fileLock != null){
>                System.out.println("File is locked");
>                accessTheLockedFile();
>            }
>
> Here is link with sample code:
> http://www.javabeat.net/tips/37-locking-files-using-java.html
>
> The problem is on linux where you can obtain lock on copying file..
> We solved this problem by renaming file with correct extension after copying
> was complete...
>
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/io-FileMonitor-How-to-deal-with-a-huge-file-whom-copy-is-longer-than-file-monitor-checkAndNotify-caly-tp3477448p3477469.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [io] FileMonitor. How to deal with a huge file whom copy is longer than file monitor checkAndNotify call frequency

Damien Tacheron
In reply to this post by JavaDev7
It works fine.

Thanks a lot

 *Damien Tacheron*
Chef de projet
------------------------------
SQLI Paris
standard : 01 55 93 26 00
ligne directe : 01 55 93 02 51
<[hidden email]>



2011/4/27 JavaDev7 <[hidden email]>

> Hi,
>
> on windows, it is simple to detect if file was copied or is copying..
> You should start thread and check if you can obtain lock on file if not
> you sleep on some period and then try again..
>
> Try:
> FileChannel fileChannel = file.getChannel();
>  fileLock = fileChannel.tryLock();
>            if (fileLock != null){
>                System.out.println("File is locked");
>                accessTheLockedFile();
>            }
>
> Here is link with sample code:
> http://www.javabeat.net/tips/37-locking-files-using-java.html
>
> The problem is on linux where you can obtain lock on copying file..
> We solved this problem by renaming file with correct extension after
> copying
> was complete...
>
> --
> View this message in context:
> http://apache-commons.680414.n4.nabble.com/io-FileMonitor-How-to-deal-with-a-huge-file-whom-copy-is-longer-than-file-monitor-checkAndNotify-caly-tp3477448p3477469.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>