aspose file tools*
The moose likes I/O and Streams and the fly likes Converting ZipOutputStream to byte[] or ByteArrayOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Converting ZipOutputStream to byte[] or ByteArrayOutputStream" Watch "Converting ZipOutputStream to byte[] or ByteArrayOutputStream" New topic
Author

Converting ZipOutputStream to byte[] or ByteArrayOutputStream

ten jones
Greenhorn

Joined: Apr 29, 2011
Posts: 4
I am having the worst time figuring this out and I haven't found a solution close to what I need anywhere online.

We are using EJB, 11g and ADF to create a system where the user can download an xml file and all images pertaining to the xml file in one, clean zip package by clicking a button/link. The download must appear as a standard "Open, Save, Cancel" user prompt ( CUSTOMERS REQUEST)

I created the xml, I can pull the images from the SQL DB and I believe they are being input into my instance of ZipOutputStream, but the problem is returning the ZipOutputStream. The system plays friendly returning ByteArrayOutputStream pdfs, docs and images so I wanted to return the zip file the same way.

With our faces-config.xml, I cannot return values exactly how I need to. I have to go through response and context.


Below is where the files are pulled and stored in the ZipOutputStream...



And this is where it is returned as a request...


Note where the bytearray needs to be. Is this possible?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

I don't understand why you are writing your zipped data to a FileOutputStream. That isn't what you want. And I don't understand why you ask how to write your zipped data to a byte array, either, because that isn't what you want. You want to write your zipped data to the response's output stream, don't you? If that's what you are saying, then just do this:
ten jones
Greenhorn

Joined: Apr 29, 2011
Posts: 4
I'm not understanding that solution. I need the. exact inverse of that.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

I don't know what you mean by "the exact inverse of that".

What I posted sends the zipped data to the response's output stream. I can't imagine what an "exact inverse" of that process would be. But anyway, your response suggests that you didn't want to send the zipped data to the response's output stream. I was under the impression that was your requirement.

But apparently it isn't. So how about a description of your requirement? What do you propose to do with that zipped data?
Wim Folkerts
Greenhorn

Joined: Mar 10, 2010
Posts: 19

The requirements are indeed not very clear. I assume Ten Jones wants to return the zipoutputstream. Doing this you may want to use the ServletOutputStream. See below a quick example


Hope this helps,
Wim
 
Don't get me started about those stupid light bulbs.
 
subject: Converting ZipOutputStream to byte[] or ByteArrayOutputStream