• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

downloading & writting file >> caching

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic