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, 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.