Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on ZipInputStream and encoding

 
Jitesh Sinha
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic