Recovering from premature connection closure

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Recovering from premature connection closure

This post has NOT been accepted by the mailing list yet.
I'm trying to implement simple response caching in a Restlet application. My current approach is to wrap the OutputStream provided to my OutputRepresentation subclass's write() method in a TeeOutputStream[1], along with a FileOutputStream which writes to a cache file.

This works well except that when the connection is closed before the full representation is written, the file written from the FileOutputStream is left incomplete -- when it really needs to get deleted immediately (because it's corrupt).

Is there an ideal or recommended way of dealing with this situation?

As a last resort, I guess I can write the cache file before writing the response, but that will be less efficient.