Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Detecting end of file transmission

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic