// Properties Table
PropertyTable properties =
- new PropertyTable(
- header_block.getBigBlockSize(),
- header_block.getPropertyStart(),
- data_blocks);
+ new PropertyTable(header_block, data_blocks);
// Mini Fat
BlockList sbat =
HeaderBlock header_block = new HeaderBlock(stream);
// read the rest of the stream into blocks
- RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
+ RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
// set up the block allocation table (necessary for the
// data_blocks to be manageable
// get property table from the document
PropertyTable properties =
- new PropertyTable(header_block.getBigBlockSize(),
- header_block.getPropertyStart(),
- data_blocks);
+ new PropertyTable(header_block, data_blocks);
// process documents
processProperties(SmallBlockTableReader
// get property table from the document
PropertyTable properties =
- new PropertyTable(bigBlockSize,
- header_block.getPropertyStart(),
- data_blocks);
+ new PropertyTable(header_block, data_blocks);
// init documents
processProperties(
class PropertyFactory
{
-
// no need for an accessible constructor
private PropertyFactory()
{
*
* @exception IOException if any of the blocks are empty
*/
-
- static List convertToProperties(ListManagedBlock [] blocks)
+ static List<Property> convertToProperties(ListManagedBlock [] blocks)
throws IOException
{
- List properties = new ArrayList();
-
- for (int j = 0; j < blocks.length; j++)
- {
- byte[] data = blocks[ j ].getData();
- int property_count = data.length
- / POIFSConstants.PROPERTY_SIZE;
- int offset = 0;
-
- for (int k = 0; k < property_count; k++)
- {
- switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ])
- {
-
- case PropertyConstants.DIRECTORY_TYPE :
- properties
- .add(new DirectoryProperty(properties.size(),
- data, offset));
- break;
-
- case PropertyConstants.DOCUMENT_TYPE :
- properties.add(new DocumentProperty(properties.size(),
- data, offset));
- break;
-
- case PropertyConstants.ROOT_TYPE :
- properties.add(new RootProperty(properties.size(),
- data, offset));
- break;
-
- default :
- properties.add(null);
- break;
- }
- offset += POIFSConstants.PROPERTY_SIZE;
- }
+ List<Property> properties = new ArrayList<Property>();
+
+ for (int j = 0; j < blocks.length; j++) {
+ byte[] data = blocks[ j ].getData();
+ convertToProperties(data, properties);
}
return properties;
}
+
+ static void convertToProperties(byte[] data, List<Property> properties)
+ throws IOException
+ {
+ int property_count = data.length / POIFSConstants.PROPERTY_SIZE;
+ int offset = 0;
+
+ for (int k = 0; k < property_count; k++) {
+ switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ]) {
+ case PropertyConstants.DIRECTORY_TYPE :
+ properties.add(
+ new DirectoryProperty(properties.size(), data, offset)
+ );
+ break;
+
+ case PropertyConstants.DOCUMENT_TYPE :
+ properties.add(
+ new DocumentProperty(properties.size(), data, offset)
+ );
+ break;
+
+ case PropertyConstants.ROOT_TYPE :
+ properties.add(
+ new RootProperty(properties.size(), data, offset)
+ );
+ break;
+
+ default :
+ properties.add(null);
+ break;
+ }
+
+ offset += POIFSConstants.PROPERTY_SIZE;
+ }
+ }
+
} // end package scope class PropertyFactory
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.BATManaged;
import org.apache.poi.poifs.storage.BlockWritable;
+import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.poifs.storage.PropertyBlock;
import org.apache.poi.poifs.storage.RawDataBlockList;
* @exception IOException if anything goes wrong (which should be
* a result of the input being NFG)
*/
- public PropertyTable(final POIFSBigBlockSize bigBlockSize,
- final int startBlock,
+ public PropertyTable(final HeaderBlock headerBlock,
final RawDataBlockList blockList)
throws IOException
{
- _bigBigBlockSize = bigBlockSize;
+ _bigBigBlockSize = headerBlock.getBigBlockSize();
_start_block = POIFSConstants.END_OF_CHAIN;
_blocks = null;
- _properties =
- PropertyFactory
- .convertToProperties(blockList.fetchBlocks(startBlock, -1));
+ _properties = PropertyFactory.convertToProperties(
+ blockList.fetchBlocks(headerBlock.getPropertyStart(), -1)
+ );
populatePropertyTree(( DirectoryProperty ) _properties.get(0));
}
*/
public void preWrite()
{
- Property[] properties = _properties.toArray(new Property[ 0 ]);
+ Property[] properties = _properties.toArray(new Property[_properties.size()]);
// give each property its index
for (int k = 0; k < properties.length; k++)
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
+import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.poifs.storage.RawDataBlockList;
import org.apache.poi.poifs.storage.RawDataUtil;
new BlockAllocationTableReader(
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
+ // Fake up a header
+ HeaderBlock header_block = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+ header_block.setPropertyStart(0);
+
// get property table from the document
- PropertyTable table = new PropertyTable(
- POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 0, data_blocks);
+ PropertyTable table = new PropertyTable(header_block, data_blocks);
assertEquals(30 * 64, table.getRoot().getSize());
int count = 0;
// need to initialize the block list with a block allocation
// table
new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
+
+ // Fake up a header
+ HeaderBlock header_block = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+ header_block.setPropertyStart(0);
// get property table from the document
- PropertyTable properties = new PropertyTable(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 0, data_blocks);
+ PropertyTable properties = new PropertyTable(header_block, data_blocks);
RootProperty root = properties.getRoot();
BlockList bl = SmallBlockTableReader.getSmallDocumentBlocks(
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, data_blocks, root, 14);