List of usage examples for org.apache.poi.openxml4j.opc.internal ZipHelper openZipFile
public static ZipSecureFile openZipFile(String path) throws IOException
From source file:com.philips.his.pixiu.cdr.poi.BigGridDemo.java
License:Apache License
/** * * @param zipfile/*from w ww . jav a2 s .co m*/ * the template file * @param tmpfile * the XML file with the sheet data * @param entry * the name of the sheet entry to substitute, e.g. xl/worksheets/sheet1.xml * @param out * the stream to write the result to */ private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException { ZipFile zip = ZipHelper.openZipFile(zipfile); try { ZipOutputStream zos = new ZipOutputStream(out); Enumeration<? extends ZipEntry> en = zip.entries(); while (en.hasMoreElements()) { ZipEntry ze = en.nextElement(); if (!ze.getName().equals(entry)) { zos.putNextEntry(new ZipEntry(ze.getName())); InputStream is = zip.getInputStream(ze); copyStream(is, zos); is.close(); } } zos.putNextEntry(new ZipEntry(entry)); InputStream is = new FileInputStream(tmpfile); copyStream(is, zos); is.close(); zos.close(); } finally { zip.close(); } }