Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

downloading & writting file >> caching  RSS feed

 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- I am keeping a set of files in session as ByteArrayStream objects.
- Based on the user's request respective file/files is/are zipped and downloaded.
- First time I download, I am getting the file size and file correctly. But if I make a repeat filedownload request I am noticing the file size is zero bytes.

I am guessing this is bcoz the ZipOutputStream(wrapper to OutputStream)is empty as I have made request for that.

How can I make the streams available until the session expires? I would like to prevent reading the same files per request from database. Instead, I would like to read and keep them in cache.

How can I achieve this?

Thanks in advance to all the reviewers.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would bet your problem is that a stream can only be read once. Your second request tries to read the already-read byte array input stream and gets end-of-file immediately. You could try to mark() the beginning of the stream and reset() after reading it (be warned that this comes with some overhead). If that doesn't work, just cache the data (byte array) and create a new stream with each request. I'd prefer the latter, especially if you anticipate multiple simultaneous requests.
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jess. You are right. I have kept the byte[] in session and changing it to stream as and when required.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!