everyone。使用java rest客戶端獲取zip文件(restEasy)
我開始使用restEasy(jboss)java rest客戶端,並遇到了一個我似乎無法解決的問題。 到目前爲止,我可以使用它從其他服務器(字符串表單)返回json。 但是,我需要的其餘服務之一將帶回一個zip文件。我偶然發現了一個問題。 下面是代碼:
ClientRequest req = new ClientRequest("rest service url"); //the url is good
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, I print the name of the first file in my archive, so, I seem to have a
// zip file indeed
String jsonString = IOUtils.toString(zip);
//bam, this is causing a zipException : invalid block type
谷歌告訴我,這是讀取壓縮文件的正確方法。我試圖逐字節讀取它,並在zip.read()中引發sams異常。
我做錯了什麼? 我該怎麼做才能閱讀我的文件內容?
如果對此事有任何見解,我會很樂意。 謝謝
P.S:對不起,如果我聽起來很奇怪,英語不是我的第一語言。
這個伎倆!非常感謝 ! – DeH