mirror of https://github.com/apache/poi.git
#57919 Add in-place and new-File write methods to POIDocument
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753619 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
667cfcb196
commit
efb790ef95
|
@ -338,7 +338,7 @@ public abstract class POIDocument implements Closeable {
|
||||||
*
|
*
|
||||||
* @throws IOException thrown on errors writing to the file
|
* @throws IOException thrown on errors writing to the file
|
||||||
*/
|
*/
|
||||||
//public abstract void write() throws IOException; // TODO Implement elsewhere
|
public abstract void write() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the document out to the specified new {@link File}. If the file
|
* Writes the document out to the specified new {@link File}. If the file
|
||||||
|
@ -348,7 +348,7 @@ public abstract class POIDocument implements Closeable {
|
||||||
*
|
*
|
||||||
* @throws IOException thrown on errors writing to the file
|
* @throws IOException thrown on errors writing to the file
|
||||||
*/
|
*/
|
||||||
//public abstract void write(File newFile) throws IOException; // TODO Implement elsewhere
|
public abstract void write(File newFile) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the document out to the specified output stream. The
|
* Writes the document out to the specified output stream. The
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hpsf;
|
package org.apache.poi.hpsf;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -44,14 +45,36 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
|
||||||
super(fs);
|
super(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write out to the currently open file the properties changes, but nothing else
|
||||||
|
*/
|
||||||
|
public void write() throws IOException {
|
||||||
|
NPOIFSFileSystem fs = directory.getFileSystem();
|
||||||
|
|
||||||
|
validateInPlaceWritePossible();
|
||||||
|
writeProperties(fs, null);
|
||||||
|
fs.writeFilesystem();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Write out, with any properties changes, but nothing else
|
||||||
|
*/
|
||||||
|
public void write(File newFile) throws IOException {
|
||||||
|
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
|
||||||
|
write(fs);
|
||||||
|
fs.writeFilesystem();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Write out, with any properties changes, but nothing else
|
* Write out, with any properties changes, but nothing else
|
||||||
*/
|
*/
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem();
|
NPOIFSFileSystem fs = new NPOIFSFileSystem();
|
||||||
|
write(fs);
|
||||||
|
fs.writeFilesystem(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write(NPOIFSFileSystem fs) throws IOException {
|
||||||
// For tracking what we've written out, so far
|
// For tracking what we've written out, so far
|
||||||
List<String> excepts = new ArrayList<String>(1);
|
List<String> excepts = new ArrayList<String>(2);
|
||||||
|
|
||||||
// Write out our HPFS properties, with any changes
|
// Write out our HPFS properties, with any changes
|
||||||
writeProperties(fs, excepts);
|
writeProperties(fs, excepts);
|
||||||
|
@ -59,7 +82,6 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
|
||||||
// Copy over everything else unchanged
|
// Copy over everything else unchanged
|
||||||
EntryUtils.copyNodes(directory, fs.getRoot(), excepts);
|
EntryUtils.copyNodes(directory, fs.getRoot(), excepts);
|
||||||
|
|
||||||
// Save the resultant POIFSFileSystem to the output stream
|
// Caller will save the resultant POIFSFileSystem to the stream/file
|
||||||
fs.writeFilesystem(out);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1301,7 +1301,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* you must use {@link #write(OutputStream)} or {@link #write(File)} to
|
* you must use {@link #write(OutputStream)} or {@link #write(File)} to
|
||||||
* write to a brand new document.
|
* write to a brand new document.
|
||||||
*/
|
*/
|
||||||
//@Override // TODO Not yet on POIDocument
|
@Override
|
||||||
public void write() throws IOException {
|
public void write() throws IOException {
|
||||||
validateInPlaceWritePossible();
|
validateInPlaceWritePossible();
|
||||||
|
|
||||||
|
@ -1330,7 +1330,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* @exception IOException if anything can't be written.
|
* @exception IOException if anything can't be written.
|
||||||
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
|
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
|
||||||
*/
|
*/
|
||||||
//@Override // TODO Not yet on POIDocument
|
@Override
|
||||||
public void write(File newFile) throws IOException {
|
public void write(File newFile) throws IOException {
|
||||||
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
|
POIFSFileSystem fs = POIFSFileSystem.create(newFile);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -47,17 +47,17 @@ public abstract class POIReadOnlyDocument extends POIDocument {
|
||||||
/**
|
/**
|
||||||
* Note - writing is not yet supported for this file format, sorry.
|
* Note - writing is not yet supported for this file format, sorry.
|
||||||
*/
|
*/
|
||||||
// @Override
|
@Override
|
||||||
// public void write() throws IOException {
|
public void write() throws IOException {
|
||||||
// throw new IllegalStateException("Writing is not yet implemented for this Document Format");
|
throw new IllegalStateException("Writing is not yet implemented for this Document Format");
|
||||||
// }
|
}
|
||||||
/**
|
/**
|
||||||
* Note - writing is not yet supported for this file format, sorry.
|
* Note - writing is not yet supported for this file format, sorry.
|
||||||
*/
|
*/
|
||||||
// @Override
|
@Override
|
||||||
// public void write(File file) throws IOException {
|
public void write(File file) throws IOException {
|
||||||
// throw new IllegalStateException("Writing is not yet implemented for this Document Format");
|
throw new IllegalStateException("Writing is not yet implemented for this Document Format");
|
||||||
// }
|
}
|
||||||
/**
|
/**
|
||||||
* Note - writing is not yet supported for this file format, sorry.
|
* Note - writing is not yet supported for this file format, sorry.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -545,6 +545,15 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
|
||||||
currentUser.setCurrentEditOffset(usr.getLastOnDiskOffset());
|
currentUser.setCurrentEditOffset(usr.getLastOnDiskOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write() throws IOException {
|
||||||
|
throw new IllegalStateException("Coming soon!");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void write(File newFile) throws IOException {
|
||||||
|
throw new IllegalStateException("Coming soon!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes out the slideshow file the is represented by an instance
|
* Writes out the slideshow file the is represented by an instance
|
||||||
* of this class.
|
* of this class.
|
||||||
|
@ -554,6 +563,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
|
||||||
* @throws IOException If there is an unexpected IOException from
|
* @throws IOException If there is an unexpected IOException from
|
||||||
* the passed in OutputStream
|
* the passed in OutputStream
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
// Write out, but only the common streams
|
// Write out, but only the common streams
|
||||||
write(out,false);
|
write(out,false);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.poi.hwpf;
|
package org.apache.poi.hwpf;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -581,6 +582,15 @@ public final class HWPFDocument extends HWPFDocumentCore
|
||||||
return _fields;
|
return _fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write() throws IOException {
|
||||||
|
throw new IllegalStateException("Coming soon!");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void write(File newFile) throws IOException {
|
||||||
|
throw new IllegalStateException("Coming soon!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes out the word file that is represented by an instance of this class.
|
* Writes out the word file that is represented by an instance of this class.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hwpf;
|
package org.apache.poi.hwpf;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@ -154,6 +155,14 @@ public class HWPFOldDocument extends HWPFDocumentCore {
|
||||||
return _text;
|
return _text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write() throws IOException {
|
||||||
|
throw new IllegalStateException("Writing is not available for the older file formats");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void write(File out) throws IOException {
|
||||||
|
throw new IllegalStateException("Writing is not available for the older file formats");
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
throw new IllegalStateException("Writing is not available for the older file formats");
|
throw new IllegalStateException("Writing is not available for the older file formats");
|
||||||
|
|
Loading…
Reference in New Issue