/** * 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"); } }
/** * 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"); } }
@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(); } } }