Class ExcelStreamHelper

java.lang.Object
fr.becpg.repo.helper.ExcelStreamHelper

public final class ExcelStreamHelper extends Object

Writes a streamed workbook to a file every spreadsheet application can open.

A streamed workbook is written to a plain output stream, so its writer does not know the size of an entry before writing it and leaves that size out of the local header of the zip entry, to publish it in a trailing data descriptor. Spreadsheet applications reading the local headers - LibreOffice among them - then declare the file corrupted and offer to repair it, although its content is complete. The entries are therefore copied, still compressed, into a file the zip writer can seek back into to complete each header.
Version:
$Id: $Id
Author:
matthieu
  • Field Details

  • Constructor Details

    • ExcelStreamHelper

      private ExcelStreamHelper()
  • Method Details

    • writeWorkbook

      public static void writeWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook workbook, File target) throws IOException

      Write the given streamed workbook to the target file.

      Parameters:
      workbook - a SXSSFWorkbook object
      target - a File object
      Throws:
      IOException - if the workbook cannot be written
    • repack

      private static void repack(File source, File target) throws IOException
      Copy every entry of a zip file, as compressed as it already is, into a seekable one.
      Parameters:
      source - a File object
      target - a File object
      Throws:
      IOException - if an entry cannot be copied
    • deleteQuietly

      private static void deleteQuietly(File file)