2012-11-16 25 views
3

我想解壓上傳到servlet的文件,並將所有解壓縮的文件作爲byte []存儲到DataStore中。由於GAE中沒有文件系統,我必須將所有內容都放在內存中。假設我有byte [] allzipdata來存儲原始的zip文件數據。如何解壓縮文件,特別是如何從每個內存中的zipentry獲取輸入流?在內存中解壓縮爲Google App Engine Java

ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(allzipdata)); 
ZipEntry ze = zis.getNextEntry(); 
while(ze!=null){ 
} 

那麼什麼是在while循環?此外,如果我上傳一個文件,我知道contentType使用item.getContentType();其中項目是FileItemStream。所以對於一個zipentry,有沒有辦法知道contentType?

回答

4

要從ZipInputStream中讀取圖像數據,我建議使用Apache Commons-IO庫。它將輸入流的ZIP條目轉換爲字節數組:

ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(allzipdata)); 
    ZipEntry ze = null; 
    while ((ze = zis.getNextEntry()) != null) { 
     // write your code to use zip entry e.g. below: 
     String filename = ze.getName(); 
     System.out.println("File Name of Entry file="+fileName); 
     byte[] data = IOUtils.toByteArray(zis); 
     // now work with the image `data` 
    } 
+0

存在拼寫錯誤fileName var聲明不具有駱駝表示法。 –