java - How to get input stream of contents of a zip file? -


i have input stream of zip file web service response. zip file contains 1 xml file. need extract input stream of xml file input stream of zip file. please help.i have tried below code.but no success.

datahandler datahandler = oddocclient.getuniquedoc(null, null); inputstream = datahandler.getinputstream(); zipinputstream zipinputstream = new zipinputstream(inputstream); zipentry zipentry=zipinputstream.getnextentry();             file tempzipfile= new file("d:\\workspace\\invoicing\\zip\\tempzip1.zip"); fileoutputstream fileoutputstream= new fileoutputstream(tempzipfile); ioutils.copy(inputstream, fileoutputstream); inputstream.close(); inputstream.close(); fileoutputstream.close(); zipfile zipfile = new zipfile(tempzipfile);  inputstream=zipfile.getinputstream(zipentry); 

this input stream used further.

with above code getting following exception.

java.util.zip.zipexception: invalid end header (bad central directory offset)     @ java.util.zip.zipfile.open(native method)     @ java.util.zip.zipfile.<init>(zipfile.java:215)     @ java.util.zip.zipfile.<init>(zipfile.java:145)     @ java.util.zip.zipfile.<init>(zipfile.java:159) 

can try this, here variable "is" inputstream, time bean cast long int in array size in code have read stream properly.

zipinputstream zis = new zipinputstream(is);         zipentry ze;     while((ze=zis.getnextentry()) != null){         if(!ze.isdirectory() && ze.getname().endswith(".xml")) {                             byte[] arr = new byte[(int)ze.getsize()]; // array of size in zip entry             zis.read(arr);             // contains here              system.out.println(new string(arr));         } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -