/** * Called during a {@link #write()} to ensure that the Document (and * associated {@link POIFSFileSystem}) was opened in a way compatible * with an in-place write. * * @throws IllegalStateException if the document was opened suitably */ protected void validateInPlaceWritePossible() throws IllegalStateException { if (directory == null) { throw new IllegalStateException("Newly created Document, cannot save in-place"); } if (directory.getParent() != null) { throw new IllegalStateException("This is not the root Document, cannot save embedded resource in-place"); } if (directory.getFileSystem() == null || !directory.getFileSystem().isInPlaceWriteable()) { throw new IllegalStateException("Opened read-only or via an InputStream, a Writeable File is required"); } }
/** * Writes out the updated standard Document Information Properties (HPSF) * into the currently open NPOIFSFileSystem * * @throws IOException if an error when writing to the open * {@link POIFSFileSystem} occurs */ protected void writeProperties() throws IOException { validateInPlaceWritePossible(); writeProperties(directory.getFileSystem(), null); }
/** * Write out to the currently open file the properties changes, but nothing else */ public void write() throws IOException { POIFSFileSystem fs = getDirectory().getFileSystem(); validateInPlaceWritePossible(); writeProperties(fs, null); fs.writeFilesystem(); } /**
/** * Write out this workbook to the currently open {@link File} via the * writeable {@link POIFSFileSystem} it was opened as. * * <p>This will fail (with an {@link IllegalStateException} if the * Workbook was opened read-only, opened from an {@link InputStream} * instead of a File, or if this is not the root document. For those cases, * you must use {@link #write(OutputStream)} or {@link #write(File)} to * write to a brand new document. */ @Override public void write() throws IOException { validateInPlaceWritePossible(); final DirectoryNode dir = getDirectory(); // Update the Workbook stream in the file DocumentNode workbookNode = (DocumentNode)dir.getEntry( getWorkbookDirEntryName(dir)); POIFSDocument workbookDoc = new POIFSDocument(workbookNode); workbookDoc.replaceContents(new ByteArrayInputStream(getBytes())); // Update the properties streams in the file writeProperties(); // Sync with the File on disk dir.getFileSystem().writeFilesystem(); }
root.getFileSystem().close();
root.getFileSystem().close();
/** * Return the underlying POIFS FileSystem of * this document. * * @deprecated Use {@link #getRoot()} instead */ public POIFSFileSystem getFileSystem() { return _dir.getFileSystem(); }
/** * Returns the underlying POIFSFileSystem for the document * that is open. */ protected POIFSFileSystem getPOIFSFileSystem() { return directory.getFileSystem(); }
/** * Return the underlying POIFS FileSystem of * this document. * * @deprecated Use {@link #getRoot()} instead */ public POIFSFileSystem getFileSystem() { return _dir.getFileSystem(); }
/** * Return the underlying POIFS FileSystem of this document. * * @deprecated Use {@link #getRoot()} instead */ @Deprecated public POIFSFileSystem getFileSystem() { return document.directory.getFileSystem(); } }
/** * Return the underlying POIFS FileSystem of this document. * * @deprecated Use {@link #getRoot()} instead */ @Deprecated public POIFSFileSystem getFileSystem() { return document.directory.getFileSystem(); } }
/** * Called during a {@link #write()} to ensure that the Document (and * associated {@link POIFSFileSystem}) was opened in a way compatible * with an in-place write. * * @throws IllegalStateException if the document was opened suitably */ protected void validateInPlaceWritePossible() throws IllegalStateException { if (directory == null) { throw new IllegalStateException("Newly created Document, cannot save in-place"); } if (directory.getParent() != null) { throw new IllegalStateException("This is not the root Document, cannot save embedded resource in-place"); } if (directory.getFileSystem() == null || !directory.getFileSystem().isInPlaceWriteable()) { throw new IllegalStateException("Opened read-only or via an InputStream, a Writeable File is required"); } }
/** * Writes out the updated standard Document Information Properties (HPSF) * into the currently open NPOIFSFileSystem * * @throws IOException if an error when writing to the open * {@link POIFSFileSystem} occurs */ protected void writeProperties() throws IOException { validateInPlaceWritePossible(); writeProperties(directory.getFileSystem(), null); }
/** * Write out the word file that is represented by this class, to the * currently open {@link File}, via the writeable {@link POIFSFileSystem} * it was opened as. * * <p>This will fail (with an {@link IllegalStateException} if the * Document was opened read-only, opened from an {@link InputStream} * instead of a File, or if this is not the root document. For those cases, * you must use {@link #write(OutputStream)} or {@link #write(File)} to * write to a brand new document. * * @since 3.15 */ @Override public void write() throws IOException { validateInPlaceWritePossible(); // Update the Document+Properties streams in the file write(getDirectory().getFileSystem(), false); // Sync with the File on disk getDirectory().getFileSystem().writeFilesystem(); }
/** * Writes out the slideshow to the currently open file. * <p> * <p>This will fail (with an {@link IllegalStateException} if the * slideshow was opened read-only, opened from an {@link InputStream} * instead of a File, or if this is not the root document. For those cases, * you must use {@link #write(OutputStream)} or {@link #write(File)} to * write to a brand new document. * * @throws IOException thrown on errors writing to the file * @throws IllegalStateException if this isn't from a writable File * @since POI 3.15 beta 3 */ @Override public void write() throws IOException { validateInPlaceWritePossible(); // Write the PowerPoint streams to the current FileSystem // No need to do anything to other streams, already there! write(getDirectory().getFileSystem(), false); // Sync with the File on disk getDirectory().getFileSystem().writeFilesystem(); }
@Override public void close() throws IOException { // only close the filesystem, if we are based on the root node. // embedded documents/slideshows shouldn't close the parent container if (getDirectory().getParent() == null) { POIFSFileSystem fs = getDirectory().getFileSystem(); if (fs != null) { fs.close(); } } }
/** * Write out to the currently open file the properties changes, but nothing else */ public void write() throws IOException { POIFSFileSystem fs = getDirectory().getFileSystem(); validateInPlaceWritePossible(); writeProperties(fs, null); fs.writeFilesystem(); } /**
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public DocumentInputStream(DocumentEntry document) throws IOException { if (!(document instanceof DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; DirectoryNode parentNode = (DirectoryNode)document.getParent(); if(documentNode.getDocument() != null) { delegate = new ODocumentInputStream(document); } else if(parentNode.getFileSystem() != null) { delegate = new ODocumentInputStream(document); } else if(parentNode.getNFileSystem() != null) { delegate = new NDocumentInputStream(document); } else { throw new IOException("No FileSystem bound on the parent, can't read contents"); } }
/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public DocumentInputStream(DocumentEntry document) throws IOException { if (!(document instanceof DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; DirectoryNode parentNode = (DirectoryNode)document.getParent(); if(documentNode.getDocument() != null) { delegate = new ODocumentInputStream(document); } else if(parentNode.getFileSystem() != null) { delegate = new ODocumentInputStream(document); } else if(parentNode.getNFileSystem() != null) { delegate = new NDocumentInputStream(document); } else { throw new IOException("No FileSystem bound on the parent, can't read contents"); } }
/** * Write out this workbook to the currently open {@link File} via the * writeable {@link POIFSFileSystem} it was opened as. * * <p>This will fail (with an {@link IllegalStateException} if the * Workbook was opened read-only, opened from an {@link InputStream} * instead of a File, or if this is not the root document. For those cases, * you must use {@link #write(OutputStream)} or {@link #write(File)} to * write to a brand new document. */ @Override public void write() throws IOException { validateInPlaceWritePossible(); final DirectoryNode dir = getDirectory(); // Update the Workbook stream in the file DocumentNode workbookNode = (DocumentNode)dir.getEntry( getWorkbookDirEntryName(dir)); POIFSDocument workbookDoc = new POIFSDocument(workbookNode); workbookDoc.replaceContents(new ByteArrayInputStream(getBytes())); // Update the properties streams in the file writeProperties(); // Sync with the File on disk dir.getFileSystem().writeFilesystem(); }