public void close() throws IOException { // Do we have a pending buffer for the mini stream? if (_buffer != null) { // It's not much data, so ask POIFSDocument to do it for us _document.replaceContents(new ByteArrayInputStream(_buffer.toByteArray())); } else { // We've been writing to the stream as we've gone along // Update the details on the property now _stream_output.close(); _property.updateSize(_document_size); _property.setStartBlock(_stream.getStartBlock()); } // No more! _closed = true; }
/** * Set the contents of a document, creating if needed, * otherwise updating. Returns the created / updated DocumentEntry * * @param name the name of the new or existing DocumentEntry * @param stream the InputStream from which to populate the DocumentEntry * * @return the new or updated DocumentEntry * * @exception IOException if the document can't be created or its content be replaced */ @SuppressWarnings("WeakerAccess") public DocumentEntry createOrUpdateDocument(final String name, final InputStream stream) throws IOException { if (! hasEntry(name)) { return createDocument(name, stream); } else { DocumentNode existing = (DocumentNode)getEntry(name); POIFSDocument nDoc = new POIFSDocument(existing); nDoc.replaceContents(stream); return existing; } }
/** * 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(); }
public void close() throws IOException { // Do we have a pending buffer for the mini stream? if (_buffer != null) { // It's not much data, so ask POIFSDocument to do it for us _document.replaceContents(new ByteArrayInputStream(_buffer.toByteArray())); } else { // We've been writing to the stream as we've gone along // Update the details on the property now _stream_output.close(); _property.updateSize(_document_size); _property.setStartBlock(_stream.getStartBlock()); } // No more! _closed = true; }
/** * Set the contents of a document, creating if needed, * otherwise updating. Returns the created / updated DocumentEntry * * @param name the name of the new or existing DocumentEntry * @param stream the InputStream from which to populate the DocumentEntry * * @return the new or updated DocumentEntry * * @exception IOException if the document can't be created or its content be replaced */ @SuppressWarnings("WeakerAccess") public DocumentEntry createOrUpdateDocument(final String name, final InputStream stream) throws IOException { if (! hasEntry(name)) { return createDocument(name, stream); } else { DocumentNode existing = (DocumentNode)getEntry(name); POIFSDocument nDoc = new POIFSDocument(existing); nDoc.replaceContents(stream); return existing; } }
/** * 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(); }