IntelliJ Java IDE
The moose likes I/O and Streams and the fly likes Streams but no IO allowed Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Streams but no IO allowed" Watch "Streams but no IO allowed" New topic
Author

Streams but no IO allowed

Leo Madrid
Greenhorn

Joined: Nov 09, 2009
Posts: 13
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

Joined: Jan 03, 2004
Posts: 3133
Look into ByteArrayInputStream and ByteArrayOutputStream. Those let you read and write bytes against arrays in memory.
Leo Madrid
Greenhorn

Joined: Nov 09, 2009
Posts: 13
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

Joined: Jan 03, 2004
Posts: 3133
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18370

Jeff Verdegan wrote:

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


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18370

 
 
subject: Streams but no IO allowed
 
Threads others viewed
A Design Question
How to download a csv file through java without using input and output streams
i need to read files with dateformat filename from a folder
Generating XML feed for users.
FTP Put a zip file that contains text files in Linux
jQuery in Action, 2nd edition