You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Damien Tacheron <dt...@sqli.com> on 2011/04/27 09:34:49 UTC

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

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
<dt...@hotmail.fr>

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

Posted by Damien Tacheron <dt...@sqli.com>.
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
<dt...@hotmail.fr>



2011/4/27 JavaDev7 <us...@post.sk>

> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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

Posted by Andrew Thorburn <nz...@gmail.com>.
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 <us...@post.sk> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


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

Posted by JavaDev7 <us...@post.sk>.
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org