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();
 }
  private static void exportOpenDocumentSpreadsheet(
      File file, BibDatabase database, List<BibEntry> entries) throws Exception {

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

    // Then add the content to the zip file:
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile))) {
      OpenDocumentSpreadsheetCreator.storeOpenDocumentSpreadsheetFile(file, in);
    }
    // Delete the temporary file:
    if (!tmpFile.delete()) {
      LOGGER.info("Cannot delete temporary export file");
    }
  }
 @Override
 public void performExport(
     final BibDatabaseContext databaseContext,
     final String file,
     final Charset encoding,
     List<BibEntry> entries)
     throws Exception {
   Objects.requireNonNull(databaseContext);
   Objects.requireNonNull(entries);
   if (!entries.isEmpty()) { // Only export if entries exists
     OpenDocumentSpreadsheetCreator.exportOpenDocumentSpreadsheet(
         new File(file), databaseContext.getDatabase(), entries);
   }
 }
  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);
    }
  }