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

Streams but no IO allowed  RSS feed

 
Leo Madrid
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!