Document extends OdfSchemaDocument implements TableContainer { public void save(OutputStream out) throws Exception { flushDoms(); updateMetaData(); if (!isRootDocument()) { Document newDoc = loadDocumentFromTemplate(getOdfMediaType()); newDoc.insertDocument(this, ROOT_DOCUMENT_PATH); newDoc.updateMetaData(); newDoc.mPackage.save(out); } else { mPackage.save(out); } } protected  Document(OdfPackage pkg, String internalPath, OdfMediaType mediaType); static Document loadDocument(String documentPath, String password); static Document loadDocument(String documentPath); static Document loadDocument(InputStream inStream); static Document loadDocument(File file); static Document loadDocument(File file, String password); static Document loadDocument(OdfPackage odfPackage); static Document loadDocument(OdfPackage odfPackage, String internalPath); void setPassword(String password); Document getEmbeddedDocument(String documentPath); List<Document> getEmbeddedDocuments(); List<Document> getEmbeddedDocuments(OdfMediaType mediaType); void insertDocument(OdfPackageDocument sourceDocument, String documentPath); Meta getOfficeMetadata(); void save(OutputStream out); void save(File file); void save(File file, String password); @Override void close(); OdfElement getContentRoot(); @Override String toString(); String newImage(URI imageUri); void setLocale(Locale locale); static ScriptType getScriptType(Locale locale); void setLocale(Locale locale, ScriptType scriptType); Locale getLocale(ScriptType scriptType); Iterator<Section> getSectionIterator(); Section getSectionByName(String name); boolean removeElementLinkedResource(OdfElement odfElement); Table addTable(); Table addTable(int numRows, int numCols); Table getTableByName(String name); java.util.List<Table> getTableList(); TableBuilder getTableBuilder(); TableTemplate LoadTableTemplateFromForeignTable(InputStream templateFileInputStream,
        String tableName);  }
@Test public void testSave() throws Exception { try { Document doc = Document.loadDocument(ResourceUtilities.getAbsolutePath("test2.odt")); Assert.assertNotNull(doc); String docmedia = doc.getOdfMediaType().getMediaTypeString(); Document doctest = Document.loadDocument(ResourceUtilities.getAbsolutePath("test2.odt")); doctest.save(ResourceUtilities.newTestOutputFile("testSave.odt")); String filePath = ResourceUtilities.getAbsolutePath("testSave.odt"); File outerFile = new File(filePath); if(!outerFile.exists()){ System.out.println("outerFile is not exist. "); } Assert.assertNotNull(doc); OutputStream out = new FileOutputStream(outerFile); doc.save(out); doc.save(ResourceUtilities.newTestOutputFile("testSave.odt")); out.close(); Document docnew = Document.loadDocument(ResourceUtilities.getTestResourceAsStream("testSave.odt")); Assert.assertNotNull(docnew); String docnewMedia = docnew.getOdfMediaType().getMediaTypeString(); Assert.assertEquals(docmedia, docnewMedia); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage(), e); Assert.fail(e.getMessage()); } }