• 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

Convert OutputStream to byte[]

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I�m trying to make a download of a zip file, and the return of the method that makes the zip is an ZipOutputStream, and the ServletOutputStream takes in it�s write() method an byte[], i�ve try to convert into an ByteArrayOutputStream but exception ClassCastException is raised.

please help!!!
cheers
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are having trouble with the concept of streams in Java. Not unusual. Check here for a tutorial
In your case, what you want to do is create a ZipOutputStream by passing the ServletOutputStream instance to the ZipOutputStream's constructor. This will compress whatever you send to the client. Create a ZipEntry instance using the name of the file you want to compress and call putNextEntry() on the ZipOutputStream. Write your file to the ZipOutputStream, flush and close.
 
reply
    Bookmark Topic Watch Topic
  • New Topic