views:

50

answers:

1

I'm writing a code that generates a large XML document and writes it directly into a client stream using StAX XmlStreamWriter. I'm afraid that if the network becomes extremely slow, the bytes written into the stream will actually stay in memory buffers for a relatively long time and consume a lot of memory on my server.

My question is: is there any way I can keep writing directly to the client stream, and avoid the potential memory problem I described above?

+1  A: 

There wouldn't seem to be if you generate faster then you can stream out it has to be in memory. If this does become a major problem you would need to look at a way to move it out of memory such as generating a file but that still needs to be loaded and streamed by something. The main advantage of a file is if you can reuse the file for many requests.

Jeff Beck
Yes, this is the best option I know, but I was hoping someone will come with some kind of a magic :)
Shai
Sorry no wizard here.
Jeff Beck