You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Brad <cx...@javawork.co.uk> on 2008/08/18 18:25:59 UTC

JAXRS: passing temp files to ResponseBuilder.entityt()

Hi all,

I've run into a bit of a problem with removing temp files that have
been set as the response entity. We are writing large files to disk
and them setting them as the response entity but obviously without a
way to delete them they will steadily increase in number. I've had a
look through the API and I can't see any way of telling it to delete
the file after it has been streamed to the client.

Is there any way to do this? Something along the lines of
Response.entity(File responseBody, boolean deleteAfter).

Thanks,
Brad,.

Re: JAXRS: passing temp files to ResponseBuilder.entityt()

Posted by Brad <cx...@javawork.co.uk>.
Dan,

good thinking there, that has done the trick.

Thanks,
Brad.

On Mon, Aug 18, 2008 at 5:33 PM, Daniel Kulp <dk...@apache.org> wrote:
>
>
> Could you do something like:
>
> Response.entity(new FileInputStream(responseBody) {
>   public void close() throws IOException {
>       super.close();
>       responseBody.delete();
>   }
> };
>
> Thus, when the stream is closed, the file would get deleted.
>
> Dan
>
>
> On Monday 18 August 2008 12:25:59 pm Brad wrote:
>> Hi all,
>>
>> I've run into a bit of a problem with removing temp files that have
>> been set as the response entity. We are writing large files to disk
>> and them setting them as the response entity but obviously without a
>> way to delete them they will steadily increase in number. I've had a
>> look through the API and I can't see any way of telling it to delete
>> the file after it has been streamed to the client.
>>
>> Is there any way to do this? Something along the lines of
>> Response.entity(File responseBody, boolean deleteAfter).
>>
>> Thanks,
>> Brad,.
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>

Re: JAXRS: passing temp files to ResponseBuilder.entityt()

Posted by Daniel Kulp <dk...@apache.org>.

Could you do something like:

Response.entity(new FileInputStream(responseBody) {
   public void close() throws IOException {
       super.close();
       responseBody.delete();
   }
};

Thus, when the stream is closed, the file would get deleted.

Dan


On Monday 18 August 2008 12:25:59 pm Brad wrote:
> Hi all,
>
> I've run into a bit of a problem with removing temp files that have
> been set as the response entity. We are writing large files to disk
> and them setting them as the response entity but obviously without a
> way to delete them they will steadily increase in number. I've had a
> look through the API and I can't see any way of telling it to delete
> the file after it has been streamed to the client.
>
> Is there any way to do this? Something along the lines of
> Response.entity(File responseBody, boolean deleteAfter).
>
> Thanks,
> Brad,.



-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog