private static void exportOpenDocumentSpreadsheet(
      File file, BibDatabase database, Set<String> keySet) throws Exception {

    // First store the xml formatted content to a temporary file.
    File tmpFile = File.createTempFile("opendocument", null);
    OpenDocumentSpreadsheetCreator.exportOpenDocumentSpreadsheetXML(tmpFile, database, keySet);

    // Then add the content to the zip file:
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile))) {
      OpenDocumentSpreadsheetCreator.storeOpenDocumentSpreadsheetFile(file, in);
    }
    // Delete the temporary file:
    tmpFile.delete();
  }
 private static void addResourceFile(String name, String resource, ZipOutputStream out)
     throws IOException {
   ZipEntry zipEntry = new ZipEntry(name);
   out.putNextEntry(zipEntry);
   OpenDocumentSpreadsheetCreator.addFromResource(resource, out);
   out.closeEntry();
 }
 @Override
 public void performExport(
     final BibDatabase database,
     final MetaData metaData,
     final String file,
     final Charset encoding,
     Set<String> keySet)
     throws Exception {
   OpenDocumentSpreadsheetCreator.exportOpenDocumentSpreadsheet(new File(file), database, keySet);
 }
  private static void storeOpenDocumentSpreadsheetFile(File file, InputStream source)
      throws Exception {

    try (ZipOutputStream out =
        new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {

      // addResourceFile("mimetype", "/resource/ods/mimetype", out);
      ZipEntry ze = new ZipEntry("mimetype");
      String mime = "application/vnd.oasis.opendocument.spreadsheet";
      ze.setMethod(ZipEntry.STORED);
      ze.setSize(mime.length());
      CRC32 crc = new CRC32();
      crc.update(mime.getBytes());
      ze.setCrc(crc.getValue());
      out.putNextEntry(ze);
      for (int i = 0; i < mime.length(); i++) {
        out.write(mime.charAt(i));
      }
      out.closeEntry();

      ZipEntry zipEntry = new ZipEntry("content.xml");
      // zipEntry.setMethod(ZipEntry.DEFLATED);
      out.putNextEntry(zipEntry);
      int c;
      while ((c = source.read()) >= 0) {
        out.write(c);
      }
      out.closeEntry();

      // Add manifest (required for OOo 2.0) and "meta.xml": These are in the
      // resource/ods directory, and are copied verbatim into the zip file.
      OpenDocumentSpreadsheetCreator.addResourceFile("meta.xml", "/resource/ods/meta.xml", out);

      OpenDocumentSpreadsheetCreator.addResourceFile(
          "META-INF/manifest.xml", "/resource/ods/manifest.xml", out);
    }
  }