struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <glindh...@yahoo.com>
Subject Re: [OT] S2 Stream Result, downloading large file, advice needed
Date Fri, 22 Aug 2008 19:51:34 GMT

I'm still interested in hear any suggestions. I know that this is not
strictly an S2 issue but it is related to using a Stream result type.  If I
was writing a servlet I would just get the OutputStream and write directly
to it, putting the burden of buffering etc. onto the container.

What I decided to do (until I hear a better suggestion) is to write to a
temporary file (File.createTempFile()) then for the InputStream I created a
wrapper around FileInputStream which will delete the file when close() is
called.  This seems to work fine in the conditions I can test, not sure if
close() will be called if the user hits Cancel in the middle of a very large
download.




Greg Lindholm wrote:
> 
> Hi Folks,  
> 
> I'm using S2 Stream result type to allow users to download a CSV "file"
> that I dynamically write from records selected from a database.
> 
> First pass on this I'm using a StringWriter to write out the CSV data
> (using SuperCSV) that using the string to build a ByteArrayInputStream for
> the InputStream result.
> 
> My concern is that the results could get very large based on the the
> selection criteria the user supplies. So trying to do this all in-memory
> with a StringWriter->String->Byte[] is likely a bad idea.
> 
> I'm looking for advice on a better way of doing this?  
> I thought I could write to a temp file, but how do I ensure the file is
> deleted when the download completes?
> I also thought about using a PipedInputStream and hooking to a
> PipedOutputStream which I write to in another thread, but this seems like
> it could become overly complicated having to deal with the threads and
> database sessions and error conditions etc.
> 
> Do you know a better way?
> 
> Any advice or suggestions would be appreciated.
>   
> Thanks
> Greg
> 
> 
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-OT--S2-Stream-Result%2C-downloading-large-file%2C-advice-needed-tp19094823p19114445.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message