Search in sources :

Example 1 with ZipFileZipEntrySource

use of org.apache.poi.openxml4j.util.ZipFileZipEntrySource in project poi by apache.

the class SXSSFWorkbook method write.

/**
     * Write out this workbook to an OutputStream.
     *
     * @param stream - the java OutputStream you wish to write to
     * @exception IOException if anything can't be written.
     */
@Override
public void write(OutputStream stream) throws IOException {
    flushSheets();
    //Save the template
    File tmplFile = TempFile.createTempFile("poi-sxssf-template", ".xlsx");
    boolean deleted;
    try {
        FileOutputStream os = new FileOutputStream(tmplFile);
        try {
            _wb.write(os);
        } finally {
            os.close();
        }
        //Substitute the template entries with the generated sheet data files
        final ZipEntrySource source = new ZipFileZipEntrySource(new ZipFile(tmplFile));
        injectData(source, stream);
    } finally {
        deleted = tmplFile.delete();
    }
    if (!deleted) {
        throw new IOException("Could not delete temporary file after processing: " + tmplFile);
    }
}
Also used : ZipFileZipEntrySource(org.apache.poi.openxml4j.util.ZipFileZipEntrySource) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) TempFile(org.apache.poi.util.TempFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFileZipEntrySource(org.apache.poi.openxml4j.util.ZipFileZipEntrySource) ZipEntrySource(org.apache.poi.openxml4j.util.ZipEntrySource)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1 ZipEntrySource (org.apache.poi.openxml4j.util.ZipEntrySource)1 ZipFileZipEntrySource (org.apache.poi.openxml4j.util.ZipFileZipEntrySource)1 TempFile (org.apache.poi.util.TempFile)1