aspose file tools*
The moose likes Beginning Java and the fly likes Question on ZipInputStream and encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on ZipInputStream and encoding" Watch "Question on ZipInputStream and encoding" New topic
Author

Question on ZipInputStream and encoding

Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Hi Guyz,

I am writing client side of a rest web service.
Web Service is returning an InputStream for a zip file which has got 2 entries.
On client side I have to convert this inputstream to a Zip file.I am using ZipInputStream for this.Problem is that I am unable to preserve the encoding - it is all "???" for special characters.
I use this code -

ServletOutputStream sos = response.getOutputStream() ;
ZipOutputStream zos = new ZipOutputStream(sos) ;
ZipInputStream zis = new ZipInputStream(is) ;
ZipEntry entry ;
while(( entry = zis.getNextEntry()) != null){

byte data[] = new byte[BUFFER];
int count ;


ZipEntry entryOut = new ZipEntry(entry.getName()) ;
zos.putNextEntry(entryOut) ;

while ((count = zis.read(data, 0, BUFFER)) != -1) {
zos.write(data,0,count) ;
}


Since we do not have any constructor in ZipInputStream that accepts encoding,I do not know how I can preserve the encoding.
Is there any other way to read the InputStream coming from server side and make it available as zip file?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

What encoding is that? And where are those question marks appearing? Since you're not using a Reader or a Writer anywhere it isn't clear to me where an encoding might be used.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Are you sending a ZipFile or are you compressing what you send?

The first one is a normal binary sending of data and can be handles by Base64 or Axis or something similar. Good example is on http://wso2.org/library/1675.

The other one should be more or less what you already do. Todd wrote a good article ages ago so it is quite outdated but the principles are the same (http://www.javaworld.com/javaworld/jw-11-1998/jw-11-howto.html?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on ZipInputStream and encoding