#57919 HPSF writing better error handling, and start prep for HSLF more write methods

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753621 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2016-07-20 23:09:33 +00:00
parent b15c2b1c53
commit d240667115
2 changed files with 29 additions and 14 deletions

View File

@ -60,16 +60,24 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
*/
public void write(File newFile) throws IOException {
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
try {
write(fs);
fs.writeFilesystem();
} finally {
fs.close();
}
}
/**
* Write out, with any properties changes, but nothing else
*/
public void write(OutputStream out) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
try {
write(fs);
fs.writeFilesystem(out);
} finally {
fs.close();
}
}
private void write(NPOIFSFileSystem fs) throws IOException {

View File

@ -564,7 +564,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
@Override
public void write(OutputStream out) throws IOException {
// Write out, but only the common streams
write(out,false);
write(out, false);
}
/**
* Writes out the slideshow file the is represented by an instance
@ -577,8 +577,22 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* the passed in OutputStream
*/
public void write(OutputStream out, boolean preserveNodes) throws IOException {
// Get a new FileSystem to write into
POIFSFileSystem outFS = new POIFSFileSystem();
try {
// Write into the new FileSystem
write(outFS, preserveNodes);
// Send the POIFSFileSystem object out to the underlying stream
outFS.writeFilesystem(out);
} finally {
outFS.close();
}
}
private void write(POIFSFileSystem outFS, boolean preserveNodes) throws IOException {
// read properties and pictures, with old encryption settings where appropriate
if(_pictures == null) {
if (_pictures == null) {
readPictures();
}
getDocumentSummaryInformation();
@ -587,9 +601,6 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
HSLFSlideShowEncrypted encryptedSS = new HSLFSlideShowEncrypted(getDocumentEncryptionAtom());
_records = encryptedSS.updateEncryptionRecord(_records);
// Get a new Filesystem to write into
POIFSFileSystem outFS = new POIFSFileSystem();
// The list of entries we've written out
List<String> writtenEntries = new ArrayList<String>(1);
@ -633,13 +644,9 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
}
// If requested, write out any other streams we spot
if(preserveNodes) {
if (preserveNodes) {
EntryUtils.copyNodes(directory.getFileSystem(), outFS, writtenEntries);
}
// Send the POIFSFileSystem object out to the underlying stream
outFS.writeFilesystem(out);
outFS.close();
}
/**