diff options
author | Nick Burch <nick@apache.org> | 2011-05-12 22:10:51 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2011-05-12 22:10:51 +0000 |
commit | 8038e149d6ac875de2bafb989e1c8ea6538d536a (patch) | |
tree | 86145e03f53c554c785dea696e09a4d3d885da0e /src/java/org/apache/poi | |
parent | 8362b74f90cb31d09bf5ab3e31dcad23510f4e1e (diff) | |
download | poi-8038e149d6ac875de2bafb989e1c8ea6538d536a.tar.gz poi-8038e149d6ac875de2bafb989e1c8ea6538d536a.zip |
Fix NPOIFS creation of an empty filesystem, with create/write/read test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1102482 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r-- | src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java index 8b2f9e9ea2..fbfd04d77a 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java @@ -93,20 +93,38 @@ public class NPOIFSFileSystem extends BlockStore private POIFSBigBlockSize bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; - /** - * Constructor, intended for writing - */ - public NPOIFSFileSystem() + private NPOIFSFileSystem(boolean newFS) { _header = new HeaderBlock(bigBlockSize); _property_table = new NPropertyTable(_header); _mini_store = new NPOIFSMiniStore(this, _property_table.getRoot(), new ArrayList<BATBlock>(), _header); - _xbat_blocks = new ArrayList<BATBlock>(); + _xbat_blocks = new ArrayList<BATBlock>(); _bat_blocks = new ArrayList<BATBlock>(); _root = null; - // Data needs to initially hold just the header block - _data = new ByteArrayBackedDataSource(new byte[bigBlockSize.getBigBlockSize()]); + if(newFS) { + // Data needs to initially hold just the header block, + // a single bat block, and an empty properties section + _data = new ByteArrayBackedDataSource(new byte[bigBlockSize.getBigBlockSize()*3]); + } + } + + /** + * Constructor, intended for writing + */ + public NPOIFSFileSystem() + { + this(true); + + // Mark us as having a single empty BAT at offset 0 + _header.setBATCount(1); + _header.setBATArray(new int[] { 0 }); + _bat_blocks.add(BATBlock.createEmptyBATBlock(bigBlockSize, false)); + setNextBlock(0, POIFSConstants.FAT_SECTOR_BLOCK); + + // Now associate the properties with the empty block + _property_table.setStartBlock(1); + setNextBlock(1, POIFSConstants.END_OF_CHAIN); } /** @@ -169,7 +187,7 @@ public class NPOIFSFileSystem extends BlockStore private NPOIFSFileSystem(FileChannel channel, boolean closeChannelOnError) throws IOException { - this(); + this(false); try { // Get the header @@ -230,7 +248,7 @@ public class NPOIFSFileSystem extends BlockStore public NPOIFSFileSystem(InputStream stream) throws IOException { - this(); + this(false); ReadableByteChannel channel = null; boolean success = false; @@ -674,7 +692,7 @@ public class NPOIFSFileSystem extends BlockStore { // HeaderBlock HeaderBlockWriter hbw = new HeaderBlockWriter(_header); - hbw.writeBlock( getBlockAt(0) ); + hbw.writeBlock( getBlockAt(-1) ); // BATs for(BATBlock bat : _bat_blocks) { |