File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on ZipInputStream and encoding" Watch "Question on ZipInputStream and encoding" New topic

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 =, 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

Joined: Oct 14, 2005
Posts: 19973

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

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 (
I agree. Here's the link:
subject: Question on ZipInputStream and encoding
It's not a secret anymore!