public ZipPartStore(InputStream is) throws Docx4JException { initMaxBytes(); partByteArrays = new HashMap<String, ByteArray>(); try { ZipArchiveInputStream zis = new ZipArchiveInputStream(is); ArchiveEntry entry = null; while ((entry = zis.getNextEntry()) != null) { // How to read the data descriptor for length? ie before reading? byte[] bytes = getBytesFromInputStream( zis ); //log.debug("Extracting " + entry.getName()); policePartSize(null, bytes.length, entry.getName()); partByteArrays.put(entry.getName(), new ByteArray(bytes) ); } zis.close(); } catch (PartTooLargeException e) { throw e; } catch (Exception e) { throw new Docx4JException("Error processing zip file (is it a zip file?)", e); } }
ZipFile zipFile = new ZipFile("C:\\test.zip"); byte[] buf = new byte[65536]; Enumeration<?> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement(); int n; InputStream is = zipFile.getInputStream(zipArchiveEntry); ZipArchiveInputStream zis = new ZipArchiveInputStream(is); if (zis.canReadEntryData(zipArchiveEntry)) { while ((n = is.read(buf)) != -1) { if (n > 0) { System.out.println(new String(buf)); } } } zis.close(); }
ZipArchiveInputStream zip = new ZipArchiveInputStream(inputStream); try { ZipArchiveEntry entry = zip.getNextZipEntry(); while(entry != null) { assertEquals("README", entry.getName()); ... entry = zip.getNextZipEntry(); } } finally { zip.close(); }
try { if (zipStream != null) zipStream.close(); } catch (IOException ignored) {}
try { zis.close(); } catch (Exception e) { } try { fis.close(); } catch (Exception e) { } try { if (fos!=null) fos.close(); } catch (Exception e) { }
private List<String> getDataSetXmlList(final InputStream inputStream) throws IOException { List<String> xmlList = new ArrayList<String>(); if (inputStream == null) { return xmlList; } ZipArchiveInputStream zipInput = new ZipArchiveInputStream(inputStream); ZipArchiveEntry entry = null; try { while ((entry = zipInput.getNextZipEntry()) != null) { if (entry.isDirectory() || !entry.getName().endsWith("xml")) { continue; } byte[] buffer = new byte[(int) entry.getSize()]; IOUtils.read(zipInput, buffer); String xml = new String(buffer); xmlList.add(xml); } } finally { zipInput.close(); } return xmlList; }
iWorksZip.close();
iWorksZip.close();
public ZipPartStore(InputStream is) throws Docx4JException { initMaxBytes(); partByteArrays = new HashMap<String, ByteArray>(); try { ZipArchiveInputStream zis = new ZipArchiveInputStream(is); ArchiveEntry entry = null; while ((entry = zis.getNextEntry()) != null) { // How to read the data descriptor for length? ie before reading? byte[] bytes = getBytesFromInputStream( zis ); //log.debug("Extracting " + entry.getName()); policePartSize(null, bytes.length, entry.getName()); partByteArrays.put(entry.getName(), new ByteArray(bytes) ); } zis.close(); } catch (PartTooLargeException e) { throw e; } catch (Exception e) { throw new Docx4JException("Error processing zip file (is it a zip file?)", e); } }
zis.close(); IOUtils.closeQuietly(is); this.zipFile=new ZipFile(this.tmpFile);
/** * Find and add the entries located in the passed XAR file. * * @param xarStream an input stream to a XAR file * @throws IOException when failing to read the file * @throws XarException when failing to parse the XAR package */ public void read(InputStream xarStream) throws IOException, XarException { ZipArchiveInputStream zis = new ZipArchiveInputStream(xarStream, "UTF-8", false); try { for (ZipArchiveEntry entry = zis.getNextZipEntry(); entry != null; entry = zis.getNextZipEntry()) { if (!entry.isDirectory() && zis.canReadEntryData(entry)) { readEntry(zis, entry.getName()); } } } finally { zis.close(); } }
@Override public Set<String> execute() throws Throwable { Set<String> entryNames = new TreeSet<String>(); ContentReader reader = CONTENT_SERVICE.getReader(downloadNode, ContentModel.PROP_CONTENT); ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(reader.getContentInputStream()); try { ZipArchiveEntry zipEntry = zipInputStream.getNextZipEntry(); while (zipEntry != null) { String name = zipEntry.getName(); entryNames.add(name); zipEntry = zipInputStream.getNextZipEntry(); } } finally { zipInputStream.close(); } return entryNames; } });