If doing an in-place write, update the properties too
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753623 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
af36e63bff
commit
92a146e4b5
@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -34,6 +35,8 @@ import org.apache.poi.hpsf.SummaryInformation;
|
||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||
import org.apache.poi.poifs.filesystem.DocumentNode;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSDocument;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
@ -298,7 +301,16 @@ public abstract class POIDocument implements Closeable {
|
||||
mSet.write(bOut);
|
||||
byte[] data = bOut.toByteArray();
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(data);
|
||||
|
||||
// New or Existing?
|
||||
// TODO Use a createOrUpdate method for this to be cleaner!
|
||||
try {
|
||||
DocumentNode propSetNode = (DocumentNode)outFS.getRoot().getEntry(name);
|
||||
NPOIFSDocument propSetDoc = new NPOIFSDocument(propSetNode);
|
||||
propSetDoc.replaceContents(bIn);
|
||||
} catch (FileNotFoundException e) {
|
||||
outFS.createDocument(bIn,name);
|
||||
}
|
||||
|
||||
logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length);
|
||||
} catch(org.apache.poi.hpsf.WritingNotSupportedException wnse) {
|
||||
|
@ -1311,6 +1311,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||
NPOIFSDocument workbookDoc = new NPOIFSDocument(workbookNode);
|
||||
workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
|
||||
|
||||
// Update the properties streams in the file
|
||||
writeProperties(directory.getFileSystem(), null);
|
||||
|
||||
// Sync with the File on disk
|
||||
directory.getFileSystem().writeFilesystem();
|
||||
}
|
||||
|
@ -689,6 +689,8 @@ public class NPOIFSFileSystem extends BlockStore
|
||||
return getRoot().createDocument(name, stream);
|
||||
}
|
||||
|
||||
// TODO Add a createOrUpdateDocument method to simplify code
|
||||
|
||||
/**
|
||||
* create a new DocumentEntry in the root entry; the data will be
|
||||
* provided later
|
||||
|
Loading…
Reference in New Issue
Block a user