• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting end of file transmission

 
Jim Carey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
is there a way to detect when a file is fully transmitted? The project I am working on expects to recieve a fixed number of large files a day. The app should not start processing until the last file is fully transmitted. Will the File exist() method return true for partially received files?

thanks in advance
Jim C
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, how do you determine which is the last file?
Is it a sequential transfer(one thread read a file after another) or a concurrent one(multiple threads read different files)?

To answer your question. Exists method will return true if the file is present on the file system. Whether it is written completely or not is something that only the application writing to the file can tell.
There are ways in which the application can indicate whether the job is finished, few of them are:
1) When the writing process is underway, write to a temp file. When the writing is complete rename the file to original file name.
2) Have a file(kind of a lock file) that indicates that the process is writing to the system. When writing finishes, remove the lock file.

In the above cases, the presence of the required file or the absence of the lock file will tell that the writing is finished.

Did I answer your question?
 
Jim Carey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitesh,
Thanks for the reply.
It is a sequential file transfer. My app checks for three files, if all three are not present, the app will sleep for 30 seconds before waking and checking again. It's when the third file is present it's transmittal state is unknown. The app is time sensitive and must start processing ASAP. These files we receive are provided by an outside entity. We have no control over the write process or we would just ask them to send us a end of transmission file to signal all files have been transferred. It looks like from your response that exists() will return true if the file is not written completely.

Jim C
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!