diff options
author | Nick Burch <nick@apache.org> | 2016-07-20 11:07:29 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2016-07-20 11:07:29 +0000 |
commit | 40591cf09af65a2f7b404bf1fdf2ec5c842e83d3 (patch) | |
tree | fb3f46aab0ef0d7e400f98331b2bb220f9931fb0 /src/java/org/apache/poi/poifs/filesystem | |
parent | 76c763b0dccbce1c7a61e29f806609f3aadb729b (diff) | |
download | poi-40591cf09af65a2f7b404bf1fdf2ec5c842e83d3.tar.gz poi-40591cf09af65a2f7b404bf1fdf2ec5c842e83d3.zip |
#57919 Start on support for writing to a new File (faster than OutputStream)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753486 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs/filesystem')
-rw-r--r-- | src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index 48d75ab940..e78f18f9f1 100644 --- a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -20,6 +20,7 @@ package org.apache.poi.poifs.filesystem; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -121,6 +122,27 @@ public class POIFSFileSystem public static boolean hasPOIFSHeader(byte[] header8Bytes) { return NPOIFSFileSystem.hasPOIFSHeader(header8Bytes); } + + /** + * Creates a new {@link POIFSFileSystem} in a new {@link File}. + * Use {@link #POIFSFileSystem(File)} to open an existing File, + * this should only be used to create a new empty filesystem. + * + * @param file The file to create and open + * @return The created and opened {@link POIFSFileSystem} + */ + public static POIFSFileSystem create(File file) throws IOException { + // TODO Make this nicer! + // Create a new empty POIFS in the file + POIFSFileSystem tmp = new POIFSFileSystem(); + FileOutputStream fout = new FileOutputStream(file); + tmp.writeFilesystem(fout); + fout.close(); + tmp.close(); + + // Open it up again backed by the file + return new POIFSFileSystem(file); + } /** * read in a file and write it back out again |