Class BlockAllocationTableReader
java.lang.Object
org.docx4j.org.apache.poi.poifs.storage.BlockAllocationTableReader
This class manages and creates the Block Allocation Table, which is
basically a set of linked lists of block indices.
Each block of the filesystem has an index. The first block, the header, is skipped; the first block after the header is index 0, the next is index 1, and so on.
A block's index is also its index into the Block Allocation Table. The entry that it finds in the Block Allocation Table is the index of the next block in the linked list of blocks making up a file, or it is set to -2: end of list.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IntListprivate static org.slf4j.Loggerprivate POIFSBigBlockSizeprivate static final intMaximum number size (in blocks) of the allocation table as supported by POI.
This constant has been chosen to help POI identify corrupted data in the header block (rather than crash immediately withOutOfMemoryError). -
Constructor Summary
ConstructorsConstructorDescriptionBlockAllocationTableReader(POIFSBigBlockSize bigBlockSize) BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, int block_count, int[] block_array, int xbat_count, int xbat_index, BlockList raw_block_list) create a BlockAllocationTableReader for an existing filesystem.BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, BlockList raw_block_list) create a BlockAllocationTableReader from an array of raw data blocks -
Method Summary
Modifier and TypeMethodDescription(package private) ListManagedBlock[]fetchBlocks(int startBlock, int headerPropertiesStartBlock, BlockList blockList) walk the entries from a specified point and return the associated blocks.(package private) intgetNextBlockIndex(int index) return the next block index(package private) booleanisUsed(int index) determine whether the block specified by index is used or notstatic voidsanityCheckBlockCount(int block_count) private voidsetEntries(ListManagedBlock[] blocks, BlockList raw_blocks) Convert an array of blocks into a set of integer indices
-
Field Details
-
_logger
private static org.slf4j.Logger _logger -
MAX_BLOCK_COUNT
private static final int MAX_BLOCK_COUNTMaximum number size (in blocks) of the allocation table as supported by POI.
This constant has been chosen to help POI identify corrupted data in the header block (rather than crash immediately withOutOfMemoryError). It's not clear if the compound document format actually specifies any upper limits. For files with 512 byte blocks, having an allocation table of 65,335 blocks would correspond to a total file size of 4GB. Needless to say, POI probably cannot handle files anywhere near that size.- See Also:
-
_entries
-
bigBlockSize
-
-
Constructor Details
-
BlockAllocationTableReader
public BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, int block_count, int[] block_array, int xbat_count, int xbat_index, BlockList raw_block_list) throws IOException create a BlockAllocationTableReader for an existing filesystem. Side effect: when this method finishes, the BAT blocks will have been removed from the raw block list, and any blocks labeled as 'unused' in the block allocation table will also have been removed from the raw block list.- Parameters:
block_count- the number of BAT blocks making up the block allocation tableblock_array- the array of BAT block indices from the filesystem's headerxbat_count- the number of XBAT blocksxbat_index- the index of the first XBAT blockraw_block_list- the list of RawDataBlocks- Throws:
IOException- if, in trying to create the table, we encounter logic errors
-
BlockAllocationTableReader
BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, BlockList raw_block_list) throws IOException create a BlockAllocationTableReader from an array of raw data blocks- Parameters:
blocks- the raw dataraw_block_list- the list holding the managed blocks- Throws:
IOException
-
BlockAllocationTableReader
BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize)
-
-
Method Details
-
sanityCheckBlockCount
- Throws:
IOException
-
fetchBlocks
ListManagedBlock[] fetchBlocks(int startBlock, int headerPropertiesStartBlock, BlockList blockList) throws IOException walk the entries from a specified point and return the associated blocks. The associated blocks are removed from the block list- Parameters:
startBlock- the first block in the chainblockList- the raw data block list- Returns:
- array of ListManagedBlocks, in their correct order
- Throws:
IOException- if there is a problem acquiring the blocks
-
isUsed
boolean isUsed(int index) determine whether the block specified by index is used or not- Parameters:
index- index of block in question- Returns:
- true if the specific block is used, else false
-
getNextBlockIndex
return the next block index- Parameters:
index- of the current block- Returns:
- index of the next block (may be POIFSConstants.END_OF_CHAIN, indicating end of chain (duh))
- Throws:
IOException- if the current block is unused
-
setEntries
Convert an array of blocks into a set of integer indices- Parameters:
blocks- the array of blocks containing the indicesraw_blocks- the list of blocks being managed. Unused blocks will be eliminated from the list- Throws:
IOException
-