1 2 17 18 19 package org.apache.poi.poifs.storage; 20 21 import org.apache.poi.poifs.filesystem.BATManaged; 22 import org.apache.poi.poifs.filesystem.POIFSDocument; 23 import org.apache.poi.poifs.property.RootProperty; 24 25 import java.util.*; 26 27 import java.io.*; 28 29 35 36 public class SmallBlockTableWriter 37 implements BlockWritable, BATManaged 38 { 39 private BlockAllocationTableWriter _sbat; 40 private List _small_blocks; 41 private int _big_block_count; 42 private RootProperty _root; 43 44 50 51 public SmallBlockTableWriter(final List documents, 52 final RootProperty root) 53 { 54 _sbat = new BlockAllocationTableWriter(); 55 _small_blocks = new ArrayList(); 56 _root = root; 57 Iterator iter = documents.iterator(); 58 59 while (iter.hasNext()) 60 { 61 POIFSDocument doc = ( POIFSDocument ) iter.next(); 62 BlockWritable[] blocks = doc.getSmallBlocks(); 63 64 if (blocks.length != 0) 65 { 66 doc.setStartBlock(_sbat.allocateSpace(blocks.length)); 67 for (int j = 0; j < blocks.length; j++) 68 { 69 _small_blocks.add(blocks[ j ]); 70 } 71 } 72 } 73 _sbat.simpleCreateBlocks(); 74 _root.setSize(_small_blocks.size()); 75 _big_block_count = SmallDocumentBlock.fill(_small_blocks); 76 } 77 78 83 84 public int getSBATBlockCount() 85 { 86 return (_big_block_count + 15) / 16; 87 } 88 89 94 95 public BlockAllocationTableWriter getSBAT() 96 { 97 return _sbat; 98 } 99 100 101 102 107 108 public int countBlocks() 109 { 110 return _big_block_count; 111 } 112 113 118 119 public void setStartBlock(int start_block) 120 { 121 _root.setStartBlock(start_block); 122 } 123 124 125 126 127 136 137 public void writeBlocks(final OutputStream stream) 138 throws IOException 139 { 140 Iterator iter = _small_blocks.iterator(); 141 142 while (iter.hasNext()) 143 { 144 (( BlockWritable ) iter.next()).writeBlocks(stream); 145 } 146 } 147 148 149 } 150 | Popular Tags |