• 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

Streams but no IO allowed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I'm hoping some of you can help me with this issue which I've been trying to solve.
This is for a jsp-servlet web app using java 1.5. This is the scenario :

- I need to create 3 csv files
- I need to compress these 3 csv files into one zip file
- I need to return the zip file in the response back to the user

Here is the caveat, no writing-reading from the disk allowed. Meaning that the csv and zip files can't be stored or read from the disk. Everything must be created in memory at runtime(and of course disposed of when the servlet is done).

I know there are dozens of examples on line unfortunately almost all are disk read-write based. Any help would be appreciated.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look into ByteArrayInputStream and ByteArrayOutputStream. Those let you read and write bytes against arrays in memory.
 
Leo Madrid
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff for your response.

But every example I've seen on ByteArrayOutputStream includes a file that already exists on the disk. Perhaps my question was too vague. Basically, I'd like to be able to do code snippet ONE without having to actually write "MyFileName" to the disk. Then I'd like to perform code snippet TWO and send "MyFileName" (which of course only exists in memory) in the response.


 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leo Madrid wrote:Thanks Jeff for your response.

But every example I've seen on ByteArrayOutputStream includes a file that already exists on the disk



You don't need a file

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:


Fixed that for you. Without a reference to the ByteArrayOutputStream, you can't retrieve its contents, now can you?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Jeff Verdegan wrote:


Fixed that for you. Without a reference to the ByteArrayOutputStream, you can't retrieve its contents, now can you?



I, um, did that on purpose to encourage the OP to read the docs. Yeah, that's it.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic