This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 145
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: 18541

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 (
jQuery in Action, 2nd edition
subject: Question on ZipInputStream and encoding