Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fail safe, consistent converter application

 
Gabriel Beres
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm implementing a converter application which reads files in one format, then converts and exports in another format.
I need to make this fail save, so there should be no partly read, and partly written entries in the input/export files. It should even maintain consistent state in case of JVM shutdown. (iex, returning after restart of JVM from last successfully written message)

Any suggestion how to do this?

Thanks,
B.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gabriel Beres wrote:Hi,

I'm implementing a converter application which reads files in one format, then converts and exports in another format.
I need to make this fail save, so there should be no partly read, and partly written entries in the input/export files. It should even maintain consistent state in case of JVM shutdown. (iex, returning after restart of JVM from last successfully written message)

Any suggestion how to do this?

Thanks,
B.


It will help us help you if you show your progress to this point so we know exactly what step you need help with. What do you have working so far?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest approach is probably to write the output to a temp file, and then after it's done (and close()d), rename it to the real desired output file name. java.io.File.renameTo() should suffice if the temp and real file are on the same file system and physical disk, but I think there's an atomic rename introduced in Java 7 in some other class somewhere, so you may want to look into that.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!