Example usage for org.apache.poi.openxml4j.opc.internal ZipHelper openZipFile

List of usage examples for org.apache.poi.openxml4j.opc.internal ZipHelper openZipFile

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.opc.internal ZipHelper openZipFile.

Prototype

public static ZipSecureFile openZipFile(String path) throws IOException 

Source Link

Document

Retrieve and open as a secure zip file with the specified path.

Usage

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();
    }
}