This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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: 22862
132
Eclipse IDE Spring TypeScript Quarkus 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: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic