Getting a zip file with a java rest client (restEasy) -
everyone.
i started use resteasy (jboss) java rest client , met problem cannot seem solve. far, use bring json rest server (string form). 1 of rest service need brings zip file, however. , stumbled on problem. here code :
clientrequest req = new clientrequest("rest service url"); //the url clientresponse<string> res = null; res = req.get(string.class); zipinputstream zip = new zipinputstream(new bytearrayinputstream(res.getentity().getbytes())); zipentry zipentry = zip.getnextentry(); system.out.println(zipentry.getname()); //here, print name of first file in archive, so, seem have // zip file indeed string jsonstring = ioutils.tostring(zip); //bam, causing zipexception : invalid block type
google told me correct way read zip file. tried read byte byte, too, , throws sams exception on zip.read().
did wrong? should read content of file?
i gratefull insight on matter. thanks
p.s : sorry if sound strange, english not first language.
url url = new url("http://xyz.com/download.zip"); httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setrequestmethod("get"); intpustream in = connection.getinputstream(); fileoutputstream out = new fileoutputstream("download.zip"); copy(in, out, 1024); out.close(); public static void copy(inputstream input, outputstream output, int buffersize) throws ioexception { byte[] buf = new byte[buffersize]; int n = input.read(buf); while (n >= 0) { output.write(buf, 0, n); n = input.read(buf); } output.flush(); }
Comments
Post a Comment